From 70154eeaf1ff3805a833178a9491c491fbe61a03 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Mon, 27 Jul 2020 12:11:16 +0200 Subject: [PATCH] added new examples --- content/tutorials/basic/print.md | 10 +++++++++- content/tutorials/networks/ethernet.md | 23 +++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/content/tutorials/basic/print.md b/content/tutorials/basic/print.md index c022116..8b5f437 100644 --- a/content/tutorials/basic/print.md +++ b/content/tutorials/basic/print.md @@ -6,9 +6,17 @@ aliases: - chapter/tutorials/basic/print --- -Using the `print()` statements in your python script is quite easy. But did you know you can also concatinate strigns and variables inline? If you are formiliar with C, it's functionality is similar to the `printf()` function, but with `\n` always included. +Using the `print()` statements in your python script is quite easy. But did you know you can also concatinate strigns and variables inline? If you are familiar with C, it's functionality is similar to the `printf()` function, but with `\n` always included. ```python import machine +print("hello world") +print("hello world.", end='') # do not end line +#you can also specify different endings, like additional text, tabs or any other escape characters +for i in range(0,9): + print(".", end='') +print("\n") #feed a new line +print("\t tabbed in") +#you can specify a variable into the string as well! print("hello world: " + str(machine.rng()) + " random number" ) ``` \ No newline at end of file diff --git a/content/tutorials/networks/ethernet.md b/content/tutorials/networks/ethernet.md index d96622f..50d6f3e 100644 --- a/content/tutorials/networks/ethernet.md +++ b/content/tutorials/networks/ethernet.md @@ -6,5 +6,24 @@ aliases: - chapter/tutorials/networks/ethernet --- -Using the Power over Ethernet (PoE) adapter on the Pygate board, we are able to connect to the local area network. ->Note: Make sure you have flashed the Pygate firmware to your -py board! \ No newline at end of file +Using the PyEthernet adapter on the Pygate board, we are able to connect to the local area network. The Ethernet functionality works separately from the PoE (Power over Ethernet) feature and works without a PoE power injector attached. +>Note: Make sure you have flashed the Pygate firmware to your -py board! + +```python +from network import ETH +import time +import socket + +eth = ETH() + +eth.init("hostname") +print("connecting...") +while not eth.isconnected(): + time.sleep(1) + print(".", end='') + +print(eth.ifconfig()) +print(socket.getaddrinfo("pycom.io", 80)) +``` +>Note: If you get the error `Expected Device ID 0x8870, got 0x0`, your PoE module is not plugged in (correctly) +