diff --git a/01_LED_BLINK/led_blink.py b/01_LED_BLINK/led_blink.py new file mode 100644 index 0000000..0b5bfdf --- /dev/null +++ b/01_LED_BLINK/led_blink.py @@ -0,0 +1,11 @@ +# Code to blink the LED on NodeMCU (ESP8266). + +import machine, time + +led = machine.Pin(2, machine.Pin.OUT) + +for i in range(20): + led.off() + time.sleep_ms(500) + led.on() + time.sleep_ms(500) diff --git a/01_LED_BLINK/readme.md b/01_LED_BLINK/readme.md new file mode 100644 index 0000000..bf980e7 --- /dev/null +++ b/01_LED_BLINK/readme.md @@ -0,0 +1,12 @@ +# 01_LED_BLINK +To run the program use the following ampy command + +## MAC OS +```bash + ampy --port /dev/tty.SLAB_USBtoUART run led_blink.py +``` + +## Linux +```bash + ampy --port /dev/ttyUSB0 run wifi_connect.py +``` diff --git a/02_Connecting to Wifi/readme.md b/02_Connecting to Wifi/readme.md new file mode 100644 index 0000000..f0e20ac --- /dev/null +++ b/02_Connecting to Wifi/readme.md @@ -0,0 +1,8 @@ +# 02_Connecting_to_Wifi +This program is to connect to WiFi using NodeMCU +To run the program use the following ampy command + + +```bash + ampy --port /dev/tty.SLAB_USBtoUART run wifi_connect.py +``` diff --git a/02_Connecting to Wifi/wifi_connect.py b/02_Connecting to Wifi/wifi_connect.py new file mode 100644 index 0000000..b977084 --- /dev/null +++ b/02_Connecting to Wifi/wifi_connect.py @@ -0,0 +1,9 @@ +import network + sta_if = network.WLAN(network.STA_IF) + if not sta_if.isconnected(): + print('Connecting to network...') + sta_if.active(True) + sta_if.connect('', '') + while not sta_if.isconnected(): + pass + print('Network config:', sta_if.ifconfig()) \ No newline at end of file diff --git a/02_WiFi_CONNECT/readme.md b/02_WiFi_CONNECT/readme.md new file mode 100644 index 0000000..cc967b9 --- /dev/null +++ b/02_WiFi_CONNECT/readme.md @@ -0,0 +1,12 @@ +# 02_WiFi_CONNECT +To run the program use the following ampy command + +## MAC OS +```bash + ampy --port /dev/tty.SLAB_USBtoUART run wifi_connect.py +``` + +## Linux +```bash + ampy --port /dev/ttyUSB0 run wifi_connect.py +``` diff --git a/02_WiFi_CONNECT/wifi_connect.py b/02_WiFi_CONNECT/wifi_connect.py new file mode 100644 index 0000000..ecc2834 --- /dev/null +++ b/02_WiFi_CONNECT/wifi_connect.py @@ -0,0 +1,24 @@ +# Code to connect the NodeMCU (ESP8266) to a WiFi network. + +import network # The network module is used to configure the WiFi connection. + +sta_if = network.WLAN(network.STA_IF) # Station interface. +ap_if = network.WLAN(network.AP_IF) # Access point interface. + +# Checking if interfaces are active. +""" +Upon a fresh install the ESP8266 is configured in access point mode, so ap_if interface is active and sta_if interface is inactive. +""" +print(sta_if.active()) # Prints (on Terminal) FALSE. +print(ap_if.active()) # Prints (on Terminal) TRUE. + +sta_if.active(True) # Activate the station interface. + +sta_if.connect('ESSID', 'PASSWORD') # Replace ESSID with the network name, and PASSWORD with the password for the network. + + +print(sta_if.isconnected()) # Prints (on Terminal) TRUE if connection is established properly. + +print(sta_if.ifconfig()) # Prints (on Terminal) the IP address, netmask, gateway, DNS. + +ap_if.active(False) # To disable the access point when not in use. \ No newline at end of file diff --git a/03_RGB_LED/readme.md b/03_RGB_LED/readme.md new file mode 100644 index 0000000..ff2e697 --- /dev/null +++ b/03_RGB_LED/readme.md @@ -0,0 +1,10 @@ +# 02_RGB_LED_COLOUR_VARIATIONS +- This program is for controlling RGB LED using NodeMCU +- Run this program after setting up the hardware part. For more information visit : +[Controlling RGB LED using NOdeMCU](https://blog.thepodnet.com/nodemcu-rgb-led-using-micropython/) + +After setting up the circuit, run the program by using following ampy command in terminal + +```bash + ampy --port /dev/tty.SLAB_USBtoUART run rgb_led.py +``` diff --git a/03_RGB_LED/rgb_led.py b/03_RGB_LED/rgb_led.py new file mode 100644 index 0000000..7accd67 --- /dev/null +++ b/03_RGB_LED/rgb_led.py @@ -0,0 +1,20 @@ +import machine +import time + +blue = machine.Pin(14, machine.Pin.OUT) +red = machine.Pin(12, machine.Pin.OUT) +green = machine.Pin(13, machine.Pin.OUT) + +while True: + green.on() + time.sleep_ms(500) + green.off() + time.sleep_ms(500) + blue.off() + time.sleep_ms(500) + blue.on() + time.sleep_ms(500) + red.on() + time.sleep_ms(500) + red.off() + time.sleep_ms(500) \ No newline at end of file diff --git a/04_ACCESS_POINT/accesspoint.py b/04_ACCESS_POINT/accesspoint.py new file mode 100644 index 0000000..9a220b8 --- /dev/null +++ b/04_ACCESS_POINT/accesspoint.py @@ -0,0 +1,14 @@ +# Code to make the NodeMCU (ESP8266) an access point, so that other devices can connect to it. + +import network + +ap = network.WLAN(network.AP_IF) # Access point interface, this will be used to make the Node into a hotspot. + +ap.active(True) # Activate the Access Point interface. + +ap.config(essid="ESSID", password="PASSWORD") # Replace ESSID with the network name, and PASSWORD with the password for other devices to connect. + +print(ap.ifconfig()) # Prints (on Terminal) the IP address, netmask, gateway, DNS. + +# The following command returns True if devices are connected to the NodeMCU. +# ap_if.active() \ No newline at end of file diff --git a/04_ACCESS_POINT/readme.md b/04_ACCESS_POINT/readme.md new file mode 100644 index 0000000..38b66cb --- /dev/null +++ b/04_ACCESS_POINT/readme.md @@ -0,0 +1,12 @@ +# 04_ACCESS_POINT +To run the program use the following ampy command + +## MAC OS +```bash + ampy --port /dev/tty.SLAB_USBtoUART run accesspoint.py +``` + +## Linux +```bash + ampy --port /dev/ttyUSB0 run accesspoint.py +```