├── .gitignore
├── README.md
├── esp_motor_bot
├── motor_bot_basic.lua
└── readme.md
├── fritzing circuits
├── Basic_esp_and_3v.fzz
├── Basic_esp_and_3v_bb.jpg
├── Basic_esp_and_3v_bb.png
├── ESP8266-01 WiFi Module.fzpz
├── ESP8266-03 WiFi Module.fzpz
├── ESP8266-07 WiFi Module.fzpz
├── ESP8266-12 WiFi Module.fzpz
├── New3vSupply.fzz
├── New3vSupply_bb.png
├── RemoteLedControl.fzz
├── RemoteLedControlMin.fzz
├── RemoteLedControl_bb.png
├── RemoteLedControl_bb.svg
├── esp8266-pinout_etch_copper_top.png
├── esp8266_flasher_tester_board.fzz
├── esp_3v_usb.fzz
└── esp_3v_usb_bb.png
├── license.md
├── may_nodemcu_servo
├── NodeMcu_with_servo.fzz
├── NodeMcu_with_servo_bb.png
└── servo_test.lua
├── may_nodemcu_ws2801
├── esp8266_ws2801.fzz
└── esp8266_ws2801_bb.png
├── micropython_ws2801
├── led-strip-servo-motor-attempt.fzz
├── led-strip-servo-motor-attempt_bb.png
├── readme.md
└── servo_sweep.py
├── multiple_analog_inputs
├── circuit-breadboard-fritzing.png
├── circuit-diagram-fritzing.png
├── circuitjs-1-pin-3-transistors.txt
├── circuitjs_example.txt
├── esp-analog-thumb-stick.fzz
├── joystick-innards.png
├── joystick_read_1_pin.lua
├── joystick_read_2_npn.lua
├── joystick_read_2_resistors.lua
├── readme.md
└── video_screenshot.jpg
├── python_libs
└── direct_servo.py
├── spiderbot
├── ant_gait.py
├── ant_gait_with_turning.py
├── crab_gait.py
├── leg_by_leg_gait.py
├── leg_tests.py
├── spiderbot.py
└── spiderbot_demo.py
├── using_node_mcu.md
├── web_led
├── connect_and_blink.lua
├── connect_and_blink_nopass.lua
├── esp_blink.lua
├── hello_world_server.lua
├── led_server.lua
├── list_ap.lua
├── power_led.html
└── readme.md
└── ws2812
├── ws2812_panel.lua
├── ws_color_cycle_unfinished.lua
├── ws_led_strip.lua
├── ws_pulsate_multi.lua
└── ws_strip_pulsate.lua
/.gitignore:
--------------------------------------------------------------------------------
1 | python_libs/webrepl-master*
2 | .vscode
3 |
4 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Esp 8266 Video Series
2 |
3 | Notes, code and details for my esp8266 videos
4 |
5 | # An Introduction
6 |
7 | The Esp 8266 is a chip used in a family of modules which make it quite simple to make small and lower power devices that can connect to the internet with Wi-Fi. It can run user code, and has a number of inputs and outputs to attach sensors and devices.
8 |
9 | [](https://www.youtube.com/watch?v=bjc2h5gWnMQ)
10 |
11 | [What is the ESP 8266 and Why Am I Excited About it?](https://www.youtube.com/watch?v=bjc2h5gWnMQ)
12 |
13 | # Plans
14 |
15 | I have plans to build robots with it - but I've started with some simple demos.
16 | Among the things I'd like to build:
17 | * a robot based on 2 modified servo's with a phone as a controller.
18 | * A crawler potentially using muscle wire
19 | * A wifi buffering extension for my CnC with a Raspberry Pi backend.
20 | * 8266 based armbot - possibly using 2 together in unison.
21 | * Small cluster of cheap meshed robots - taking one as an AP with the rest as clients to it.
22 |
23 | # What I have done so far
24 |
25 | * [Powering the esp 8266](http://orionrobots.co.uk/2015/04/29/powering-the-esp8266)
26 | * [Making a wifi controlled Light with the ESP8266](http://orionrobots.co.uk/2015/06/10/esp-8266-wifi-led)
27 |
28 | # What I am doing currently
29 |
30 | Beyond collecting up my notes so the videos make more sense, I've been trying out the esp12 and esp03 modules - which have more pins for inputs and outputs than the esp01, and I've ordered a few other esp kits online for fun - including some rather neat DIP based modules with on board regulators, USB input and USB to Serial converters. When they are the same price as the esp-01, they make it far easier to experiment.
31 |
32 | I've also been attempting to put Micropython on them. Videos and demos to follow.
33 |
34 | # License
35 |
36 | CC-BY-SA 3.0
37 | [License](license.md)
38 |
39 | # Changes
40 |
41 | If you wish to propose changes, or make comments, please use the github issues or pull request system.
42 |
43 |
--------------------------------------------------------------------------------
/esp_motor_bot/motor_bot_basic.lua:
--------------------------------------------------------------------------------
1 | -- Simple ESP Motor robot
2 |
3 | -- Function to initialise a motor
4 | -- motor: motor to initialise
5 | function motor_init(motor)
6 | gpio.mode(motor.enable, gpio.OUTPUT)
7 | gpio.mode(motor.d0, gpio.OUTPUT)
8 | gpio.mode(motor.d1, gpio.OUTPUT)
9 | pwm.setup(motor.enable, 500, 1023)
10 | end
11 |
12 | -- Function to set motor forward, speed
13 | -- motor - the motor struct (table)
14 | -- speed - 0-1023 - duty cycle
15 | function motor_forward(motor, speed)
16 | gpio.write(motor.d0, 1)
17 | gpio.write(motor.d1, 0)
18 | pwm.setup(motor.enable, 500, speed)
19 | pwm.start(motor.enable)
20 | end
21 |
22 | -- Function to set motor back, speed
23 | -- motor - the motor struct (table)
24 | -- speed - 0-1023 - duty cycle
25 | function motor_backward(motor, speed)
26 | gpio.write(motor.d0, 0)
27 | gpio.write(motor.d1, 1)
28 | pwm.setup(motor.enable, 500, speed)
29 | pwm.start(motor.enable)
30 | end
31 |
32 | --Funciton motors off
33 | function motor_stop(motor)
34 | pwm.stop(motor.enable)
35 | end
36 |
37 | -- Main demo (remember to feed the watch dog!)
38 | local motora = {enable=5, d0=4, d1=3}
39 | local motorb = {enable=6, d0=1, d1=2}
40 |
41 | motor_init(motora)
42 | motor_init(motorb)
43 |
44 | motor_forward(motora, 1023)
45 | tmr.delay(500000)
46 | motor_stop(motora)
47 | tmr.wdclr()
48 |
49 | motor_forward(motorb, 1023)
50 | tmr.delay(500000)
51 | motor_stop(motorb)
52 | tmr.wdclr()
53 |
54 | motor_backward(motora, 1023)
55 | tmr.delay(500000)
56 | motor_stop(motora)
57 | tmr.wdclr()
58 |
59 | motor_backward(motorb, 1023)
60 | tmr.delay(500000)
61 | motor_stop(motorb)
62 |
--------------------------------------------------------------------------------
/esp_motor_bot/readme.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | This is an esp8266/NodeMCU based robot with 2 wheels that is both inexpensive, and a starting platform for fun and experimentation.
4 |
5 | Video: https://www.youtube.com/watch?v=ZYZelug2SW0&feature=youtu.be
6 |
7 | # Bill Of Materials
8 |
9 | * Robot Chassis - many on ebay as "smart robot chassis". These are extremely cheap, you shouldn't pay more than about £15 for it. It should have:
10 | ** The main chassis - some precut perspex.
11 | ** 2 motors with wheels - preferably with cables soldered on.
12 | ** A front castor.
13 | ** All fixing screws.
14 | * It may have:
15 | ** Encoder slots and wheels
16 | * If the chassis didn't come with one, you need a 4xAA battery box.
17 | * 4xAA batteries
18 | * SOme sticky tack, or double sided sticky pads.
19 | * A NodeMCU dev board module.
20 | * an L298N motor control module - there are designs that jumper the enable pins so they are pulled up - for the current build, remove this jumper.
21 | * A breadboard (400 point type with voltage rails)
22 | * Some breadboard jump wires - of varying lengths - get a selection of these.
23 | * 8 male to female jump wires with crimped ends.
24 |
25 | # Building it
26 |
27 | First - remove any backing from the perspex chassis.
28 |
29 | If the motors didn't come wired then solder the wires on before the next step.
30 |
31 | Bolt the motors onto the chassis.
32 | Fix the wheels onto the motors.
33 | Bolt the castor onto the chassis too.
34 |
35 | Looking at the video for reference - lay out the motor control board so the motor cables can reach it.
36 | Put the battery box at one end, and leave room for the breadboard the other.
37 |
38 | Screw the motors, and battery cables into the L298N motor controller.
39 |
40 | # Wiring the breadboard
41 |
42 | Wire the breadboard before sticking it on the chassis. This needs a bit of thought.
43 | Test fit the nodemcu on the breadboard - don't push all the way down. Note down the row numbers for pins d0-d5, vIn and Gnd.
44 | Leaving space for the ESP pins - bring the vIn and round pins to the voltage rails on the board.
45 | Then wire d1 to d6 to a space on the board, where you will attach it to the motor controller.
46 |
47 | Push the NodeMCU board into place.
48 |
49 | Attach the board to the chassis.
50 |
51 | Connect the voltage rails to the 5v and ground connections on the L298.
52 | Connect D1, 2, 3 from the ESP to ENA, 1, 2 on the L298.
53 | And
54 | D4, 5, 6 on then ESP to to 3, 4, ENB on the L298.
55 |
56 | # Code
57 |
58 | If you've not done so, flash the esp8266 with the NodeMCU firmware - I se the NodeMCU Flasher tool.
59 | Get the start code from this project and upload it. Warning - If you've already put batteries in, have a hand ready to catch the robot as it drives off the table!
60 |
61 | # Go!
62 |
63 | Put the batteries in, and press the reset button to see it move.
64 |
65 | # Problems
66 |
67 | This first needs a power switch - currently removing a battery is the only way to turn it off.
68 | Also - a few resistors may be needed between the esp and the motor controller. IT was designed for 5v use, and I noticed the esp getting a bit warm - so these could limit current if it's not being particular good with power.
69 | The L298N uses 6 io, with some jumpered designs only needing 4. Other motor controller solutions may need fewer pins - leaving them free for experimenting.
70 |
71 | These will be addressed in follow up work.
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/fritzing circuits/Basic_esp_and_3v.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/Basic_esp_and_3v.fzz
--------------------------------------------------------------------------------
/fritzing circuits/Basic_esp_and_3v_bb.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/Basic_esp_and_3v_bb.jpg
--------------------------------------------------------------------------------
/fritzing circuits/Basic_esp_and_3v_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/Basic_esp_and_3v_bb.png
--------------------------------------------------------------------------------
/fritzing circuits/ESP8266-01 WiFi Module.fzpz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/ESP8266-01 WiFi Module.fzpz
--------------------------------------------------------------------------------
/fritzing circuits/ESP8266-03 WiFi Module.fzpz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/ESP8266-03 WiFi Module.fzpz
--------------------------------------------------------------------------------
/fritzing circuits/ESP8266-07 WiFi Module.fzpz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/ESP8266-07 WiFi Module.fzpz
--------------------------------------------------------------------------------
/fritzing circuits/ESP8266-12 WiFi Module.fzpz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/ESP8266-12 WiFi Module.fzpz
--------------------------------------------------------------------------------
/fritzing circuits/New3vSupply.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/New3vSupply.fzz
--------------------------------------------------------------------------------
/fritzing circuits/New3vSupply_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/New3vSupply_bb.png
--------------------------------------------------------------------------------
/fritzing circuits/RemoteLedControl.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/RemoteLedControl.fzz
--------------------------------------------------------------------------------
/fritzing circuits/RemoteLedControlMin.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/RemoteLedControlMin.fzz
--------------------------------------------------------------------------------
/fritzing circuits/RemoteLedControl_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/RemoteLedControl_bb.png
--------------------------------------------------------------------------------
/fritzing circuits/esp8266-pinout_etch_copper_top.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/esp8266-pinout_etch_copper_top.png
--------------------------------------------------------------------------------
/fritzing circuits/esp8266_flasher_tester_board.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/esp8266_flasher_tester_board.fzz
--------------------------------------------------------------------------------
/fritzing circuits/esp_3v_usb.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/esp_3v_usb.fzz
--------------------------------------------------------------------------------
/fritzing circuits/esp_3v_usb_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/fritzing circuits/esp_3v_usb_bb.png
--------------------------------------------------------------------------------
/license.md:
--------------------------------------------------------------------------------
1 | This is under the CC-BY_SA-3.0 License.
2 |
3 | https://creativecommons.org/licenses/by-sa/3.0/
4 |
5 | This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
6 |
--------------------------------------------------------------------------------
/may_nodemcu_servo/NodeMcu_with_servo.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/may_nodemcu_servo/NodeMcu_with_servo.fzz
--------------------------------------------------------------------------------
/may_nodemcu_servo/NodeMcu_with_servo_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/may_nodemcu_servo/NodeMcu_with_servo_bb.png
--------------------------------------------------------------------------------
/may_nodemcu_servo/servo_test.lua:
--------------------------------------------------------------------------------
1 | pin = 2
2 | gpio.mode(pin, gpio.OUTPUT)
3 | -- The second parameter here is the frequency
4 | -- most hobby motors use 50. Check your model for specifics.
5 | -- 500 is the duty cycle - 512 is the middle (ish).
6 | pwm.setup(pin, 50, 512)
7 | pwm.start(pin)
8 |
9 | tmr.delay(300)
10 | pwm.setduty(pin, 100)
11 | tmr.delay(300)
12 | pwm.setduty(pin, 800)
13 |
14 |
--------------------------------------------------------------------------------
/may_nodemcu_ws2801/esp8266_ws2801.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/may_nodemcu_ws2801/esp8266_ws2801.fzz
--------------------------------------------------------------------------------
/may_nodemcu_ws2801/esp8266_ws2801_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/may_nodemcu_ws2801/esp8266_ws2801_bb.png
--------------------------------------------------------------------------------
/micropython_ws2801/led-strip-servo-motor-attempt.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/micropython_ws2801/led-strip-servo-motor-attempt.fzz
--------------------------------------------------------------------------------
/micropython_ws2801/led-strip-servo-motor-attempt_bb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/micropython_ws2801/led-strip-servo-motor-attempt_bb.png
--------------------------------------------------------------------------------
/micropython_ws2801/readme.md:
--------------------------------------------------------------------------------
1 | These were used in getting Micropython linked with a WS2801 light strip, and then for the attempt in driving servo motors from WS2801 LED strips.
2 |
3 | See the youtube video for a full explaination: https://www.youtube.com/watch?v=U06c4os9Yuk&feature=youtu.be
4 |
5 | The diagram shows an LPD8806, but the WS2801 and 8806 appear to be equivalent parts.
6 |
7 | 
8 |
9 | The file uses SPI to instruct the WS2801 lights to sweep up from 0 to 255, and then back down.
10 |
11 | I also used the library <../python_libs/direct_servo.py> to test the motor directly connected to the NodeMCU.
12 |
--------------------------------------------------------------------------------
/micropython_ws2801/servo_sweep.py:
--------------------------------------------------------------------------------
1 | """Using a WS2801 LED strip (spi) as a servo motor controller"""
2 | from machine import Pin, SPI
3 | from time import sleep
4 |
5 | # setup
6 | clock = Pin(5)
7 | mosi = Pin(4) # Out
8 | miso = Pin(2) # In - a dummy here
9 | # Presume the -1 means hware here.
10 | spi = SPI(-1, baudrate=100000, sck=clock, mosi=mosi, miso=miso)
11 | spi.init()
12 |
13 | # Loop
14 | def sweep(waitsec):
15 | for n in range(255):
16 | spi.write(bytes([n]*3))
17 | sleep(waitsec)
18 | for n in range(255, 0, -1):
19 | spi.write(bytes([n]*3))
20 | sleep(waitsec)
21 |
22 |
23 |
--------------------------------------------------------------------------------
/multiple_analog_inputs/circuit-breadboard-fritzing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/multiple_analog_inputs/circuit-breadboard-fritzing.png
--------------------------------------------------------------------------------
/multiple_analog_inputs/circuit-diagram-fritzing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/multiple_analog_inputs/circuit-diagram-fritzing.png
--------------------------------------------------------------------------------
/multiple_analog_inputs/circuitjs-1-pin-3-transistors.txt:
--------------------------------------------------------------------------------
1 | $ 1 0.000005 10.20027730826997 57 5 43
2 | t 208 224 240 224 0 1 0.5505518168244585 0.5671900837461007 100
3 | t 496 224 528 224 0 1 -2.0410658265442283 -0.5172275674428968 100
4 | s -208 192 -144 192 0 0 false
5 | r 144 224 208 224 0 10000
6 | w -208 192 -224 192 0
7 | w 240 240 240 272 0
8 | w 528 240 528 288 0
9 | w 240 320 240 272 0
10 | g 496 368 496 400 0
11 | r 496 320 496 368 0 1000
12 | w 496 320 496 288 0
13 | w 496 288 528 288 0
14 | w 496 320 240 320 0
15 | R 240 208 240 160 0 3 100 2.4 2.5 1.5707963267948966 0.5
16 | R 528 208 528 160 0 3 100 2.4 2.5 0 0.5
17 | x -270 237 -152 240 4 24 Digital\sIO\s1
18 | x 419 313 553 316 4 24 Analog\sInput
19 | x 473 136 581 139 4 24 Joystick\sY
20 | x 180 132 288 135 4 24 Joystick\sX
21 | t 176 32 208 32 0 1 0.5568101129045515 0.5693442824502074 100
22 | w 208 16 336 16 0
23 | w 64 224 144 224 0
24 | r 208 -48 208 16 0 10000
25 | r 112 32 176 32 0 10000
26 | R 208 -48 208 -80 0 0 40 3 0 0 0.5
27 | R -224 192 -224 160 0 0 40 3 0 0 0.5
28 | g 208 48 208 64 0
29 | I 96 -32 176 -32 0 0.5 5
30 | w -144 192 64 192 0
31 | w 64 192 64 224 0
32 | w 64 192 64 32 0
33 | w 64 32 112 32 0
34 | w 336 16 336 224 0
35 | w 336 224 496 224 0
36 | o 10 64 0 4102 5 0.00078125 0 3 13 0 14 0
37 |
--------------------------------------------------------------------------------
/multiple_analog_inputs/circuitjs_example.txt:
--------------------------------------------------------------------------------
1 | $ 1 0.000005 10.20027730826997 57 5 43
2 | v 16 368 16 96 0 0 40 5 0 0 0.5
3 | t 208 224 240 224 0 1 -2.3390604439248897 0.09853954519079842 100
4 | t 496 224 528 224 0 1 -4.739060443842694 0.09853954527298535 100
5 | s 96 224 144 224 0 1 false
6 | s 384 224 432 224 0 1 false
7 | r 432 224 496 224 0 10000
8 | r 144 224 208 224 0 10000
9 | w 96 224 96 64 0
10 | w 384 224 384 64 0
11 | w 384 64 192 64 0
12 | w 192 64 96 64 0
13 | w 96 64 16 64 0
14 | w 16 368 192 368 0
15 | w 192 368 480 368 0
16 | w 240 240 240 272 0
17 | w 528 240 528 288 0
18 | w 240 288 240 272 0
19 | g 192 384 192 400 0
20 | w 192 368 192 384 0
21 | r 496 320 496 368 0 1000
22 | w 480 368 496 368 0
23 | w 16 64 16 96 0
24 | w 496 320 496 288 0
25 | w 496 288 528 288 0
26 | w 496 288 240 288 0
27 | R 240 208 240 160 0 3 100 2.4 2.5 1.5707963267948966 0.5
28 | R 528 208 528 160 0 3 100 2.4 2.5 0 0.5
29 | x 94 260 212 263 4 24 Digital\sIO\s1
30 | x 371 258 489 261 4 24 Digital\sIO\s2
31 | x 419 319 553 322 4 24 Analog\sInput
32 | x 474 128 582 131 4 24 Joystick\sY
33 | x 199 127 307 130 4 24 Joystick\sX
34 | o 22 64 0 4098 0.0000762939453125 0.00078125 0 2 22 3
35 | o 25 64 0 4098 5 0.0125 1 2 25 3
36 | o 26 64 0 4098 5 0.0125 1 2 26 3
37 |
--------------------------------------------------------------------------------
/multiple_analog_inputs/esp-analog-thumb-stick.fzz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/multiple_analog_inputs/esp-analog-thumb-stick.fzz
--------------------------------------------------------------------------------
/multiple_analog_inputs/joystick-innards.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/multiple_analog_inputs/joystick-innards.png
--------------------------------------------------------------------------------
/multiple_analog_inputs/joystick_read_1_pin.lua:
--------------------------------------------------------------------------------
1 | -- Config
2 | local read_xy = 5
3 | local duration = 50 --> In milis
4 |
5 | -- Initialise the pins
6 | function init_joystick( read_xy )
7 | gpio.mode(read_xy, gpio.OUTPUT)
8 | gpio.write(read_xy, gpio.LOW)
9 | end
10 |
11 | function read_joystick( read_xy )
12 | gpio.write(read_xy, gpio.HIGH)
13 | local x = adc.read(0)
14 | gpio.write(read_xy, gpio.LOW)
15 | local y = adc.read(0)
16 | return {x, y}
17 | end
18 |
19 | print("Setting up")
20 | init_joystick(read_xy)
21 |
22 | -- Create an interval
23 |
24 | tmr.alarm(0, duration, 1, function ()
25 | local pos = read_joystick(read_xy)
26 | print("X is", pos[1], "Y is ", pos[2])
27 | end)
28 |
--------------------------------------------------------------------------------
/multiple_analog_inputs/joystick_read_2_npn.lua:
--------------------------------------------------------------------------------
1 | -- Config
2 | local read_x = 5
3 | local read_y = 6
4 | local duration = 500 --> In milis
5 |
6 | -- Initialise the pins
7 | function init_joystick( read_x, read_y )
8 | gpio.mode(read_x, gpio.OUTPUT)
9 | gpio.mode(read_y, gpio.OUTPUT)
10 | gpio.write(read_x, gpio.LOW)
11 | gpio.write(read_y, gpio.LOW)
12 | end
13 |
14 | function read_joystick( read_x, read_y )
15 | gpio.write(read_x, gpio.HIGH)
16 | local x = adc.read(0)
17 | gpio.write(read_x, gpio.LOW)
18 | gpio.write(read_y, gpio.HIGH)
19 | local y = adc.read(0)
20 | gpio.write(read_y, gpio.LOW)
21 | return {x, y}
22 | end
23 |
24 | print("Setting up")
25 | init_joystick(read_x, read_y)
26 | -- Create an interval
27 | tmr.alarm(0, duration, 1, function ()
28 | local pos = read_joystick(read_x, read_y)
29 | print("X is", pos[1], "Y is ", pos[2])
30 | end)
31 |
--------------------------------------------------------------------------------
/multiple_analog_inputs/joystick_read_2_resistors.lua:
--------------------------------------------------------------------------------
1 | -- Config
2 | local read_x = 5
3 | local read_y = 6
4 | local duration = 50 --> In milis
5 |
6 | -- Initialise the pins
7 | function init_joystick( read_x, read_y )
8 | gpio.mode(read_x, gpio.INPUT)
9 | gpio.mode(read_y, gpio.INPUT)
10 | -- gpio.write(read_x, gpio.LOW)
11 | -- gpio.write(read_y, gpio.LOW)
12 | end
13 |
14 | function read_joystick( read_x, read_y )
15 | gpio.mode(read_x, gpio.INPUT)
16 | gpio.mode(read_y, gpio.OUTPUT)
17 | gpio.write(read_y, gpio.LOW)
18 | local x = adc.read(0)
19 | gpio.mode(read_y, gpio.INPUT)
20 | gpio.mode(read_x, gpio.OUTPUT)
21 | gpio.write(read_x, gpio.LOW)
22 | local y = adc.read(0)
23 | return {x, y}
24 | end
25 |
26 | print("Setting up")
27 | init_joystick(read_x, read_y)
28 | -- Create an interval
29 | tmr.alarm(0, duration, 1, function ()
30 | local pos = read_joystick(read_x, read_y)
31 | print("X is", pos[1], "Y is ", pos[2])
32 | end)
33 |
--------------------------------------------------------------------------------
/multiple_analog_inputs/readme.md:
--------------------------------------------------------------------------------
1 | This is the source code and Circuit diagrams for using the esp8266 with 2 Analog inputs - with a thumb joystick as the inputs.
2 |
3 | See to watch how I build it.
--------------------------------------------------------------------------------
/multiple_analog_inputs/video_screenshot.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orionrobots/esp8266_video_series/a4ee80199a12c41e5499873e9f63a0bfec5ed4a9/multiple_analog_inputs/video_screenshot.jpg
--------------------------------------------------------------------------------
/python_libs/direct_servo.py:
--------------------------------------------------------------------------------
1 | """Adapted from https://bitbucket.org/thesheep/micropython-servo/src/f562a6abeaf0e83b752838df7cd31d88ea10b2c7/servo.py?at=default&fileviewer=file-view-default
2 | """
3 | from machine import PWM
4 | import math
5 |
6 |
7 | class DServo:
8 | """
9 | A simple class for controlling hobby servos.
10 |
11 | Args:
12 | pin (machine.Pin): The pin where servo is connected. Must support PWM.
13 | freq (int): The frequency of the signal, in hertz.
14 | min_us (int): The minimum signal length supported by the servo.
15 | max_us (int): The maximum signal length supported by the servo.
16 | angle (int): The angle between the minimum and maximum positions.
17 |
18 | """
19 | def __init__(self, pin, freq=50, min_us=600, max_us=2400, angle=180):
20 | self.min_us = min_us
21 | self.max_us = max_us
22 | self.us = 0
23 | self.freq = freq
24 | self.angle = angle
25 | self.pwm = PWM(pin, freq=freq, duty=0)
26 |
27 | def write_us(self, us):
28 | """Set the signal to be ``us`` microseconds long. Zero disables it."""
29 | if us == 0:
30 | self.pwm.duty(0)
31 | return
32 | us = min(self.max_us, max(self.min_us, us))
33 | duty = us * 1024 * self.freq // 1000000
34 | self.pwm.duty(duty)
35 |
36 | def write_angle(self, degrees=None, radians=None):
37 | """Move to the specified angle in ``degrees`` or ``radians``."""
38 | if degrees is None:
39 | degrees = math.degrees(radians)
40 | degrees = degrees % 360
41 | total_range = self.max_us - self.min_us
42 | us = self.min_us + total_range * degrees // self.angle
43 | self.write_us(us)
44 |
--------------------------------------------------------------------------------
/spiderbot/ant_gait.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 | import spiderbot
3 | from machine import reset
4 | from spiderbot_demo import neutral, left_side, right_side
5 |
6 | def move_group(group, knee=None, hip=None, foot=None, delay=None):
7 | """Group is a list of legs. Change all the positions
8 | as defined"""
9 | for leg in group:
10 | if foot:
11 | leg.foot.position(foot)
12 | if knee:
13 | leg.knee.position(knee)
14 | if hip:
15 | leg.hip.position(hip)
16 | if delay:
17 | sleep(delay)
18 |
19 | knees_up = 30
20 | knees_down = 90
21 |
22 | def ant_pattern(hips_range=20, position_delay=0.1, smooth_delay=0.01, smooth_speed=4):
23 | group1 = [left_side[0], right_side[1], left_side[2]]
24 | group2 = [right_side[0], left_side[1], right_side[2]]
25 | neutral(False)
26 | # Put group1 up first
27 | move_group(group1, knee=knees_up, delay=position_delay)
28 | # Starting from neutral (but knees up)
29 | while True:
30 | # Sweep group1 hips forward (in the air)
31 | # While sweeping group2 hips back
32 | for n in range(0, hips_range, smooth_speed):
33 | move_group(group1, hip=90+n)
34 | move_group(group2, hip=90-n)
35 | sleep(smooth_delay)
36 | # Now place group 1 down
37 | move_group(group1, knee=knees_down, delay=position_delay)
38 | # Pick group 2 up
39 | move_group(group2, knee=knees_up, delay=position_delay)
40 | # Now sweep the other way - group1 goes back, group1 forward, by 60
41 | for n in range(-hips_range, hips_range, smooth_speed):
42 | move_group(group1, hip=90-n)
43 | move_group(group2, hip=90+n)
44 | sleep(smooth_delay)
45 | # Place group 2 down and 1 up
46 | move_group(group2, knee=knees_down, delay=position_delay)
47 | move_group(group1, knee=knees_up, delay=position_delay)
48 | # Now half sweep group 1 forward, and 2 back (to neutral)
49 | for n in range(-hips_range, 0, smooth_speed):
50 | move_group(group1, hip=90+n)
51 | move_group(group2, hip=90-n)
52 | sleep(smooth_delay)
53 |
54 |
--------------------------------------------------------------------------------
/spiderbot/ant_gait_with_turning.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 | import spiderbot
3 | from machine import reset
4 | from spiderbot_demo import neutral, left_side, right_side, crouch
5 |
6 | class ScalingLegGroup:
7 | def __init__(self, legs, scale_indexes):
8 | self.legs = legs
9 | self.scale_indexes = scale_indexes
10 | self.scales = (1.0, 1.0)
11 |
12 | def set_scale(self, left, right):
13 | self.scales = (left, right)
14 |
15 | def get_scale(self, index):
16 | return self.scales[self.scale_indexes[index]]
17 |
18 | def iter(self):
19 | for n in range(len(self.legs)):
20 | yield self.get_scale(n), self.legs[n]
21 |
22 | def move(self, knee=None, hip=None, foot=None, delay=None):
23 | for hip_scale, leg in self.iter():
24 | if foot is not None:
25 | leg.foot.position(90 + foot)
26 | if knee is not None:
27 | leg.knee.position(90 + knee)
28 | if hip is not None:
29 | position = 90 + int(hip * hip_scale)
30 | leg.hip.position(position)
31 | if delay:
32 | sleep(delay)
33 |
34 | # Turning ant pattern
35 | def ant_gait_with_turning(hips_range=20, position_delay=0.1, smooth_delay=0.01, smooth_speed=4, left=1, right=1, knees_up=-60, knees_down=0, feet_in=-30):
36 | group1 = ScalingLegGroup(
37 | [left_side[0], right_side[1], left_side[2]],
38 | [0, 1, 0]
39 | )
40 | group2 = ScalingLegGroup(
41 | [right_side[0], left_side[1], right_side[2]],
42 | [1, 0, 1]
43 | )
44 | group1.set_scale(left, right)
45 | group2.set_scale(left, right)
46 | neutral(False)
47 | # Put group1 up first
48 | group1.move(knee=knees_up, foot=feet_in, delay=position_delay)
49 | # Starting from neutral (but kn`ees up)
50 | while True:
51 | # Sweep group1 hips forward (in the air)
52 | # While sweeping group2 hips back
53 | for n in range(0, hips_range, smooth_speed):
54 | group1.move(hip=n)
55 | group2.move(hip=-n)
56 | sleep(smooth_delay)
57 | # Now place group 1 down
58 | group1.move(knee=knees_down, foot=0, delay=position_delay)
59 | # Pick group 2 up
60 | group2.move(knee=knees_up, foot=feet_in, delay=position_delay)
61 | # Now sweep the other way - group1 goes back, group1 forward, by 60
62 | for n in range(-hips_range, hips_range, smooth_speed):
63 | group1.move(hip=-n)
64 | group2.move(hip=n)
65 | sleep(smooth_delay)
66 | # Place group 2 down and 1 up
67 | group2.move(knee=knees_down, foot=0, delay=position_delay)
68 | group1.move(knee=knees_up, foot=feet_in, delay=position_delay)
69 | # Now half sweep group 1 forward, and 2 back (to neutral)
70 | for n in range(-hips_range, 0, smooth_speed):
71 | group1.move(hip=n)
72 | group2.move(hip=-n)
73 | sleep(smooth_delay)
74 |
--------------------------------------------------------------------------------
/spiderbot/crab_gait.py:
--------------------------------------------------------------------------------
1 | from math import sin, radians
2 | from spiderbot_demo import *
3 |
4 | def crab(delay=0.02, direction=1):
5 | # Wobbling knees
6 | theta = 0
7 | neutral(release=False)
8 | while True:
9 | group1_knees = 90 + int(sin(radians(theta)) * 30)
10 | group1_feet = 90 + int(sin(radians(theta+90)) * 30)
11 | group2_knees = 90 + int(sin(radians(theta + 180)) * 30)
12 | group2_feet = 90 + int(sin(radians(theta + 270)) * 30)
13 |
14 | for leg in (left_side[0], right_side[1], left_side[2]):
15 | leg.foot.position(group1_feet)
16 | leg.knee.position(group1_knees)
17 |
18 | for leg in (right_side[0], left_side[1], right_side[2]):
19 | leg.foot.position(group2_feet)
20 | leg.knee.position(group2_knees)
21 |
22 | sleep(delay)
23 | theta += direction
24 | if theta > 360:
25 | theta = 0
26 |
--------------------------------------------------------------------------------
/spiderbot/leg_by_leg_gait.py:
--------------------------------------------------------------------------------
1 | from spiderbot_demo import *
2 |
3 | def leg_by_leg(position_delay=0.1, smooth_delay=0.01, smooth_speed=4):
4 | neutral(release=False)
5 | pattern = [left_side[0], right_side[0], left_side[1], right_side[1], left_side[2], right_side[2]]
6 | while True:
7 | # All legs up and forward
8 | for leg in pattern:
9 | leg.knee.position(30)
10 | sleep(position_delay)
11 | leg.hip.position(110)
12 | sleep(position_delay)
13 | leg.knee.position(90)
14 | sleep(position_delay)
15 | # Now sweep back
16 | for n in range(110, 90, -smooth_speed):
17 | for leg in pattern:
18 | leg.hip.position(n)
19 | sleep(smooth_delay)
20 | sleep(position_delay)
21 |
22 |
--------------------------------------------------------------------------------
/spiderbot/leg_tests.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 | import spiderbot
3 |
4 | left_side, right_side = spiderbot.init()
5 |
6 | # feet test
7 | def feet_test(side):
8 | """Pass in left side or right side"""
9 | for leg in side:
10 | leg.foot.position(150)
11 | sleep(0.3)
12 | leg.foot.position(90)
13 | sleep(0.3)
14 |
15 | # # knee test down
16 | def knee_test(side):
17 | for leg in side:
18 | leg.knee.position(150)
19 | sleep(0.3)
20 | leg.knee.position(90)
21 | sleep(0.3)
22 | leg.knee.position(30)
23 | sleep(0.3)
24 | leg.knee.position(90)
25 | sleep(0.3)
26 |
27 | def hip_test(side):
28 | for leg in side:
29 | leg.hip.position(150)
30 | sleep(0.3)
31 | leg.hip.position(90)
32 | sleep(0.3)
33 | leg.hip.position(30)
34 | sleep(0.3)
35 | leg.hip.position(90)
36 | sleep(0.3)
37 |
--------------------------------------------------------------------------------
/spiderbot/spiderbot.py:
--------------------------------------------------------------------------------
1 | """Control for the spider bot servo's.
2 | Libraries:
3 | * micropython-adafruit-pca9685 - servo.py and pca9685.py.
4 | * https://bitbucket.org/thesheep/micropython-servo/src/f562a6abeaf0e83b752838df7cd31d88ea10b2c7/servo.py?at=default&fileviewer=file-view-default
5 | * as direct_servo.py with class DServo.
6 | """
7 | from machine import Pin, I2C
8 | import servo
9 | from direct_servo import DServo
10 |
11 | # Todo: Potentially flatten this with the other classes I have the source for.
12 | class Servo9686():
13 | def __init__(self, adafruit_servos, index):
14 | self._servos = adafruit_servos
15 | self._index = index
16 | self.invert = False
17 |
18 | def position(self, angle):
19 | if self.invert:
20 | angle = 180 - angle
21 | self._servos.position(self._index, angle)
22 |
23 | def release(self):
24 | self._servos.release(self._index)
25 |
26 |
27 | class ServoDirect():
28 | def __init__(self, pin):
29 | self._servo = DServo(pin)
30 | self.invert = False
31 |
32 | def position(self, angle):
33 | if self.invert:
34 | angle = 180 - angle
35 | self._servo.write_angle(angle)
36 |
37 | def release(self):
38 | self._servo.write_us(0)
39 |
40 |
41 | class Robot:
42 | def __init__(self, i2c):
43 | s = servo.Servos(i2c)
44 | servo_list = []
45 | for n in range(16):
46 | servo_list.append(Servo9686(s, n))
47 | servo_list.append(ServoDirect(Pin(0)))
48 | servo_list.append(ServoDirect(Pin(2)))
49 |
50 | # Set them all to 90 degrees
51 | for n in range(18):
52 | servo_list[n].position(90)
53 | self.servo_list = servo_list
54 |
55 |
56 | class Leg():
57 | def __init__(self, robot, hip, knee, foot, invert=False):
58 | """Hip, Knee and Foot are Servo classes.
59 | Invert will invert angles on hips and knees"""
60 | self.hip = robot.servo_list[hip]
61 | self.knee = robot.servo_list[knee]
62 | self.foot = robot.servo_list[foot]
63 | if invert:
64 | self.hip.invert = True
65 | self.knee.invert = True
66 | self.foot.invert = True
67 |
68 | def init():
69 | """From the front:
70 | 00
71 | --0--0--0 0--0--0--
72 | 1 0 2 4 3 5
73 | --0--0--0 0--0--0--
74 | 11 10 9 6 7 8
75 | --0--0--0 0--0--0--
76 | 14 12 13 17 15 16
77 | """
78 | i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
79 | robot = Robot(i2c)
80 |
81 | left_side = [
82 | Leg(robot, 2, 0, 1),
83 | Leg(robot, 9, 10, 11),
84 | Leg(robot, 13, 12, 14)
85 | ]
86 |
87 | right_side = [
88 | Leg(robot, 4, 3, 5, invert=True),
89 | Leg(robot, 6, 7, 8, invert=True),
90 | Leg(robot, 17, 15, 16, invert=True)
91 | ]
92 |
93 | return left_side, right_side
94 |
--------------------------------------------------------------------------------
/spiderbot/spiderbot_demo.py:
--------------------------------------------------------------------------------
1 | from time import sleep
2 | import spiderbot
3 | from machine import reset
4 |
5 | left_side, right_side = spiderbot.init()
6 |
7 | def neutral(release=True):
8 | for leg in left_side:
9 | leg.knee.position(90)
10 | leg.foot.position(90)
11 | leg.hip.position(90)
12 | for leg in right_side:
13 | leg.knee.position(90)
14 | leg.foot.position(90)
15 | leg.hip.position(90)
16 | if release:
17 | sleep(0.1)
18 | for leg in left_side:
19 | leg.knee.release()
20 | leg.foot.release()
21 | leg.hip.release()
22 | for leg in right_side:
23 | leg.knee.release()
24 | leg.foot.release()
25 | leg.hip.release()
26 |
27 | def crouch():
28 | neutral()
29 | for leg in left_side:
30 | leg.knee.position(30)
31 | for leg in right_side:
32 | leg.knee.position(30)
33 | sleep(0.1)
34 | for leg in left_side:
35 | leg.knee.release()
36 | for leg in right_side:
37 | leg.knee.release()
38 |
39 |
--------------------------------------------------------------------------------
/using_node_mcu.md:
--------------------------------------------------------------------------------
1 | So far I've found NodeMCU to be the most useful and fun way of getting things done with the esp8266. It is based aorund the Lua language. While I like the idea of Micropython, it is not as well supported for the 8266 yet.
2 |
3 |
4 | # How do I get NodeMCU Flashed Onto an 8266 with Windows
5 |
6 | ## Download the image
7 |
8 | Node MCU is right here on github at [https://github.com/nodemcu/nodemcu-firmware](https://github.com/nodemcu/nodemcu-firmware).
9 | There is a tool for use in Windows NodeMCUFlasher. It can be used to flash other code onto the 8266 as well with other images.
10 | [https://github.com/nodemcu/nodemcu-flasher/blob/master/Win64/Release/ESP8266Flasher.exe](https://github.com/nodemcu/nodemcu-flasher/blob/master/Win64/Release/ESP8266Flasher.exe)
11 |
12 | ## Find the serial port
13 |
14 | ASsuming you have got you esp8266 connected to a computer and powered, first you need to find the Serial port for it. Open up Device Manager (Windows Key, "Device Manager" on windows 8, or start, control panel, device manager).
15 |
16 | In device manager, look for COM ports - there should be a new entry there. This COM number is what you will need.
17 |
18 | ## Find the device in the flasher tool
19 |
20 | Start up the flasher above, type in your serial port details - and you should be able to detect an 8266 and flash it. Once this is done - you are ready to go.
21 |
22 |
--------------------------------------------------------------------------------
/web_led/connect_and_blink.lua:
--------------------------------------------------------------------------------
1 | -- my wifi setup
2 | wifi.setmode(wifi.STATION)
3 | wifi.sta.config("ssid","password")
4 | print(wifi.sta.getip())
5 |
6 | dofile("led_server.lua")
7 |
8 |
--------------------------------------------------------------------------------
/web_led/connect_and_blink_nopass.lua:
--------------------------------------------------------------------------------
1 | -- my wifi setup
2 | wifi.setmode(wifi.STATION)
3 | wifi.sta.config("SSID","password")
4 | print(wifi.sta.getip())
5 |
6 | -- Config
7 | local pin = 3 --> GPIO0
8 | local value = gpio.LOW
9 | local duration = 1000 --> 1 second
10 |
11 | -- Initialise the pin
12 | gpio.mode(pin, gpio.OUTPUT)
13 | gpio.write(pin, value)
14 |
15 | -- Create an interval
16 | tmr.alarm(0, duration, 1, function ()
17 | if value == gpio.LOW then
18 | value = gpio.HIGH
19 | else
20 | value = gpio.LOW
21 | end
22 |
23 | gpio.write(pin, value)
24 | end)
25 |
--------------------------------------------------------------------------------
/web_led/esp_blink.lua:
--------------------------------------------------------------------------------
1 | -- Config
2 | local pin = 3 --> GPIO0
3 | local value = gpio.LOW
4 | local duration = 1000 --> 1 second
5 |
6 | print("Setting up")
7 | -- Initialise the pin
8 | gpio.mode(pin, gpio.OUTPUT)
9 | gpio.write(pin, value)
10 |
11 | print("Starting timer")
12 | -- Create an interval
13 | tmr.alarm(0, duration, 1, function ()
14 | if value == gpio.LOW then
15 | value = gpio.HIGH
16 | print("High")
17 | else
18 | value = gpio.LOW
19 | print("Low")
20 | end
21 |
22 | gpio.write(pin, value)
23 | end)
24 |
--------------------------------------------------------------------------------
/web_led/hello_world_server.lua:
--------------------------------------------------------------------------------
1 | srv=net.createServer(net.TCP)
2 | srv:listen(80,function(conn)
3 | conn:on("receive",function(conn,payload)
4 | conn:send("Hello world!")
5 | end)
6 | conn:on("sent",function(conn) conn:close() end)
7 | end)
--------------------------------------------------------------------------------
/web_led/led_server.lua:
--------------------------------------------------------------------------------
1 | -- Back end for html led
2 |
3 | -- Config
4 | local pin = 3 --> GPIO0
5 | local value = gpio.LOW
6 |
7 |
8 | function serve_html(conn)
9 | file.open("power_led.html")
10 | conn:send(file.read())
11 | file.close()
12 | end
13 |
14 | function set_led(value)
15 | gpio.write(pin, value)
16 | end
17 |
18 | print("Initialising")
19 | print(wifi.sta.getip())
20 | gpio.mode(pin, gpio.OUTPUT)
21 | print("Creating server")
22 | srv=net.createServer(net.TCP)
23 | print("Start listening on port 80")
24 | srv:listen(80,function(conn)
25 | conn:on("receive",function(conn,payload)
26 | print(payload)
27 | if string.find(payload, "/on") then
28 | set_led(gpio.HIGH)
29 | conn:send("on")
30 | elseif string.find(payload, "/off") then
31 | set_led(gpio.LOW)
32 | conn:send("off")
33 | elseif string.find(payload, "GET / HTTP") then
34 | serve_html(conn)
35 | else
36 | print("Sending hello")
37 | conn:send("
Hello, NodeMcu.
")
38 | end
39 | end)
40 | conn:on("sent",function(conn) conn:close() end)
41 | end)
42 |
--------------------------------------------------------------------------------
/web_led/list_ap.lua:
--------------------------------------------------------------------------------
1 | -- print ap list
2 | function listap(t)
3 | for k,v in pairs(t) do
4 | print(k.." : "..v)
5 | end
6 | end
7 | wifi.sta.getap(listap)
8 |
--------------------------------------------------------------------------------
/web_led/power_led.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
16 |
17 |
18 |
LED Power
19 | on
20 | off
21 |
22 |
--------------------------------------------------------------------------------
/web_led/readme.md:
--------------------------------------------------------------------------------
1 | These are steps taken in my [web LED 8266 video series](http://orionrobots.co.uk/2015/06/10/esp-8266-wifi-led/).
2 |
3 |
4 | # Getting this running
5 |
6 | The steps in brief (details below):
7 |
8 | * Build the circuit
9 | * Flash the device with Node MCU
10 | * Play with that a bit! (there should always be play)
11 | * setup your wifi details
12 | * Use the nodemcu tools to upload the blinking led example and try it.
13 | * Use the nodemcu tools to upload the hello_world_server.lua and try it.
14 | * Use the nodemcu tools to upload the web page html.
15 | * Use the nodemcu tools to upload the led_server.lua and try this.
16 |
17 | # Bill of Materials
18 |
19 | * Small breadboard (301 pin pictured, but any will do)
20 | * esp8266 - the circuits shown are the esp-01. If you know electronics, you can use any of the esp modules here.
21 | * Red LED (for power, during testing - you can remove later)
22 | * Green LED (for controllable - you can swap these when you want)
23 | * 2 x 100 Ohm resistors (R1, R2)
24 | * 1 x 10k Ohm resistor (R3)
25 | * 1 x 3.3uF Electrolytic Capacitor
26 | * 1 x LD33V (or LD1117v33) 3.3v regulator
27 | * A bunch of jump wires - single core stiff wire for breadboarding.
28 | * 8 male to female prototyping cables.
29 |
30 | * A 6v battery box - thats 4 x AA.
31 |
32 | # Tools
33 |
34 | * A Computer
35 | * A serial adaptor - I used a USB to TTL adaptor not based on an FTDI.
36 | * Pair of needle-nosed pliers - optional, but helps to make bends in component legs.
37 |
38 | # Build the circuit
39 |
40 | There are 3 parts to the circuit.
41 |
42 | . Note here that you
53 |
--------------------------------------------------------------------------------
/ws2812/ws2812_panel.lua:
--------------------------------------------------------------------------------
1 | -- Note - this is not intended to run as a complete program - these are snippets
2 | -- for experimentation - blocks to run in Esplorer and demonstrate the panel.
3 |
4 | white = string.char(255, 255, 255)
5 | off = string.char(0,0,0)
6 | blue=string.char(0, 0, 255)
7 | pink=string.char(255, 0, 255)
8 | purple=string.char(20, 0, 20)
9 | red =string.char(100, 0, 0)
10 | green =string.char(0, 100, 0)
11 | yellow =string.char(100, 100, 0)
12 | gold =string.char(180, 100, 0)
13 | silver = string.char(60, 60, 100)
14 | orange = string.char(255/4,127/4,0)
15 | violet = string.char(138,43,226)
16 | indigo = string.char(75,0,130)
17 |
18 |
19 | rainbow_line = (red..orange..yellow..green..blue..indigo..violet..gold)
20 | ws2812.writergb(1, rainbow_line:rep(8))
21 |
22 | ws2812.writergb(1, white:rep(64))
23 | ws2812.writergb(1, off:rep(64))
24 | ws2812.writergb(1, blue:rep(64))
25 | ws2812.writergb(1, purple:rep(64))
26 | ws2812.writergb(1, red:rep(64))
27 | ws2812.writergb(1, green:rep(64))
28 | ws2812.writergb(1, gold:rep(64))
29 | ws2812.writergb(1, silver:rep(64))
30 |
31 | stripes = (red:rep(8)..blue:rep(8)
32 | ..red:rep(8)..green:rep(8)
33 | ..red:rep(8)..purple:rep(8)
34 | ..red:rep(8)..gold:rep(8))
35 |
36 | ws2812.writergb(1, stripes)
37 |
38 | -- Drawing a letter H
39 | w = white
40 | b = off
41 | letter_h = (b..w..b..b..b..b..w..b
42 | ..b..w..b..b..b..b..w..b
43 | ..b..w..b..b..b..b..w..b
44 | ..b..w..b..b..b..b..w..b
45 | ..b..w..w..w..w..w..w..b
46 | ..b..w..b..b..b..b..w..b
47 | ..b..w..b..b..b..b..w..b
48 | ..b..w..b..b..b..b..w..b)
49 | ws2812.writergb(1, letter_h)
50 |
51 | -- Letter J
52 |
53 | letter_j = (b..b..b..b..b..w..w..w
54 | ..b..b..b..b..b..b..w..b
55 | ..b..b..b..b..b..b..w..b
56 | ..b..b..b..b..b..b..w..b
57 | ..b..b..b..b..b..b..w..b
58 | ..b..b..b..b..b..b..w..b
59 | ..b..b..b..w..b..w..b..b
60 | ..b..b..b..b..w..b..b..b)
61 | ws2812.writergb(1, letter_j:gsub(w, blue))
62 |
63 | -- Word Jo
64 |
65 | word_jo = (w..w..w..b..b..b..b..b
66 | ..b..w..b..b..b..b..b..b
67 | ..b..w..b..b..b..b..b..b
68 | ..b..w..b..b..b..w..b..b
69 | ..b..w..b..b..w..b..w..b
70 | ..b..w..b..b..w..b..w..b
71 | ..w..b..b..b..b..w..b..b
72 | ..b..b..b..b..b..b..b..b
73 | )
74 | ws2812.writergb(1, word_jo:gsub(b, green))
--------------------------------------------------------------------------------
/ws2812/ws_color_cycle_unfinished.lua:
--------------------------------------------------------------------------------
1 | red = 0
2 | green = 1
3 | blue = 2
4 | purple = 3
5 | yellow = 4
6 |
7 | masks = {{255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {255, 0, 255], {255, 255, 0}}
8 | pin = 1
9 | leds = 29
10 |
11 | --Multi Pulsate
12 | current = 1
13 | current_dir = 4
14 | current_colour = 0
15 |
16 | tmr.alarm(0, 20, 1, function()
17 | current = current + current_dir
18 | if current_dir > 0 and current >= 250 then
19 | current_dir = masks:len-4
20 | elseif current_dir < 0 and current <= 1 then
21 | current_dir = 4
22 | current_colour = current_colour + 1
23 | current_colour = current_colour % 4
24 | end
25 | if current_colour == red then
26 | colour = string.char(current % 255, 0, 0)
27 | elseif current_colour == green then
28 | colour = string.char(0, current % 255, 0)
29 | elseif current_colour == blue then
30 | colour = string.char(0, 0, current % 255)
31 | else
32 | colour = string.char(current % 255, 0, current % 255)
33 | end
34 | ws2812.writergb(1, colour:rep(leds))
35 | end)
36 |
37 |
38 |
--------------------------------------------------------------------------------
/ws2812/ws_led_strip.lua:
--------------------------------------------------------------------------------
1 |
2 | white = string.char(255, 255, 255)
3 | red = string.char(255, 0, 0)
4 | green = string.char(0, 255, 0)
5 | blue = string.char(0, 0, 255)
6 | off = string.char (0, 0, 0)
7 | purple = string.char(60, 0, 60)
8 | yellow = string.char(60, 60, 0)
9 |
10 | ws2812.writergb(1, red..green..blue..purple..white..off:rep(29))
11 | tmr.delay(10000)
12 | ws2812.writergb(1, off:rep(29))
13 | tmr.delay(10000)
14 |
15 | pin = 1
16 | leds = 64
17 |
18 |
19 | current = 1
20 | current_dir = 1
21 | current_seq = red..blue..green..purple
22 | yellow_cur = leds
23 | yellow_dir = -1
24 | tmr.alarm(0, 100, 1, function()
25 | current = current + current_dir
26 | if current_dir == 1 and current >= leds-3 then
27 | current_dir = -1
28 | elseif current_dir == -1 and current <= 1 then
29 | current_dir = 1
30 | end
31 | yellow_cur = leds - current
32 | if yellow_cur > current then
33 | dist = yellow_cur - current - 4
34 | ws2812.writergb(1, off:rep(current-1)..current_seq..off:rep(dist)..yellow..off:rep(leds))
35 | elseif yellow_cur < current then
36 | dist = current - yellow_cur
37 | ws2812.writergb(1, off:rep(yellow_cur-1)..yellow..off:rep(dist)..current_seq..off:rep(leds))
38 | else
39 | ws2812.writergb(1, off:rep(current-1)..current_seq..off:rep(leds))
40 | end
41 | end)
42 |
43 |
44 |
--------------------------------------------------------------------------------
/ws2812/ws_pulsate_multi.lua:
--------------------------------------------------------------------------------
1 | red = 0
2 | green = 1
3 | blue = 2
4 | purple = 3
5 |
6 | pin = 1
7 | leds = 29
8 |
9 | --Multi Pulsate
10 | current = 1
11 | current_dir = 4
12 | current_colour = 0
13 |
14 | tmr.alarm(0, 20, 1, function()
15 | current = current + current_dir
16 | if current_dir > 0 and current >= 250 then
17 | current_dir = -4
18 | elseif current_dir < 0 and current <= 1 then
19 | current_dir = 4
20 | current_colour = current_colour + 1
21 | current_colour = current_colour % 4
22 | end
23 | if current_colour == red then
24 | colour = string.char(current % 255, 0, 0)
25 | elseif current_colour == green then
26 | colour = string.char(0, current % 255, 0)
27 | elseif current_colour == blue then
28 | colour = string.char(0, 0, current % 255)
29 | else
30 | colour = string.char(current % 255, 0, current % 255)
31 | end
32 | ws2812.writergb(1, colour:rep(leds))
33 | end)
34 |
35 |
36 |
--------------------------------------------------------------------------------
/ws2812/ws_strip_pulsate.lua:
--------------------------------------------------------------------------------
1 | pin = 1
2 | leds = 64
3 | --Pulsate
4 | current = 1
5 | current_dir = 4
6 |
7 | tmr.alarm(0, 20, 1, function()
8 | current = current + current_dir
9 | if current_dir > 0 and current >= 250 then
10 | current_dir = -4
11 | elseif current_dir < 0 and current <= 1 then
12 | current_dir = 4
13 | end
14 | colour = string.char(current % 255, 0, 0)
15 | ws2812.writergb(1, colour:rep(leds))
16 | end)
17 |
18 |
19 |
--------------------------------------------------------------------------------