added NodeMCU code and documentation

master
Simon Pirkelmann 2019-04-10 15:55:16 +02:00
parent 6ec11ef846
commit 57738814b6
17 changed files with 196 additions and 0 deletions

BIN
docu/EXP Tech.pdf Normal file

Binary file not shown.

BIN
docu/chassis_datasheet.pdf Normal file

Binary file not shown.

BIN
docu/l293_datasheet.pdf Normal file

Binary file not shown.

BIN
docu/nodeMCU_pinout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

9
docu/notes.txt Normal file
View File

@ -0,0 +1,9 @@
https://hackaday.com/2016/06/14/hackaday-prize-entry-micro-robots-for-education/
https://www.adafruit.com/product/3216
https://www.exp-tech.de/plattformen/robotik/roboterfahrzeuge/7673/adafruit-mini-round-robot-chassis-kit-2wd-with-dc-motors?gclid=EAIaIQobChMIrpHIq4Ke4QIVSeAYCh0LTgdWEAQYCCABEgIQcfD_BwE
https://www.exp-tech.de/plattformen/robotik/roboterfahrzeuge/7898/adafruit-mini-3-layer-round-robot-chassis-kit-2wd-with-dc-motors?gclid=EAIaIQobChMIrpHIq4Ke4QIVSeAYCh0LTgdWEAQYCyABEgI76vD_BwE

21
docu/pin_out.txt Normal file
View File

@ -0,0 +1,21 @@
Breadboard | NodeMCU, GPIO, index | H-bridge
-------------------------------------
13 | D0, 16, 0 | 15 # driver channel 4 input
14 | D1, 5, 1 | 10 # driver channel 3 input
15 | D2, 4, 2 | 9 # driver 3/4 enable (pwm)
16 | D3, 0, 3 | 2 # driver channel 2 input
17 | D4, 2, 4 | 7 # driver channel 1 input
20 | D5, 14, 5 | 1 # driver 1/2 enable (pwm)
26 | GND
Motor example:
First motor:
GPIO16 -> HIGH (index 0)
GPIO05 -> LOW (index 1)
GPIO04 -> HIGH (index 2)
Second motor:
GPIO00 -> HIGH (index 3)
GPIO02 -> LOW (index 4)
GPIO14 -> HIGH (index 5)

Binary file not shown.

View File

@ -0,0 +1,2 @@
esptool.py --port /dev/ttyUSB0 write_flash -fm qio 0x00000 nodemcu-master-9-modules-2019-04-08-19-43-38-float.bin

46
nodemcu_firmware/init.lua Normal file
View File

@ -0,0 +1,46 @@
dofile('motor.lua')
cfg={}
cfg.ssid="robot-1"
cfg.pwd="roborally"
wifi.ap.config(cfg)
sv = net.createServer()
Peer = {}
function Peer:create(sck)
local peer = {}
setmetatable(peer, Peer)
peer.buffer = {}
return peer
end
function Peer:receive(sck, data)
self.buffer = self.buffer .. data
if #self.buffer >= 4 then
dir = string.byte(self.buffer,1)
if dir > 127 then dir = -256+dir end
motor_dir(1, dir)
dir = string.byte(self.buffer,2)
if dir > 127 then dir = -256+dir end
motor_dir(2, dir)
delay = string.byte(self.buffer,3) * 256 + string.byte(self.buffer, 4)
tmr.delay(delay)
motor_dir(1, 0)
motor_dir(2, 0)
self.buffer = {}
sck:close()
end
end
if sv then
-- listen to port 80 and call callback function if data is received
sv:listen(80,
function(conn)
peer = Peer:create(conn)
conn:on("receive", peer:receive(conn))
conn:send("robot-1 at your service")
end)
end

View File

@ -0,0 +1,28 @@
motor = {}
motor[1] = {}
motor[1][1] = 0
motor[1][2] = 1
motor[1][3] = 2
motor[2] = {}
motor[2][1] = 3
motor[2][2] = 4
motor[2][3] = 5
for i,m in ipairs(motor) do
for i,g in ipairs(m) do
gpio.mode(g, gpio.OUTPUT)
gpio.write(g, 1)
end
end
function motor_dir(m, dir)
if dir ~= 0 then
gpio.write(motor[m][3], 1)
gpio.write(motor[m][1], (1-dir)/2)
gpio.write(motor[m][2], (1+dir)/2)
else
gpio.write(motor[m][3], 0)
end
end

View File

@ -0,0 +1,28 @@
motor = {}
motor[1] = {}
motor[1][1] = 0
motor[1][2] = 1
motor[1][3] = 2
motor[2] = {}
motor[2][1] = 3
motor[2][2] = 4
motor[2][3] = 5
for i,m in ipairs(motor) do
for i,g in ipairs(m) do
gpio.mode(g, gpio.OUTPUT)
gpio.write(g, 1)
end
end
function motor_dir(m, dir)
if dir ~= 0 then
gpio.write(motor[m][3], 1)
gpio.write(motor[m][1], (1-dir)/2)
gpio.write(motor[m][2], (1+dir)/2)
else
gpio.write(motor[m][3], 0)
end
end

View File

@ -0,0 +1,47 @@
motor = {}
motor[1] = {}
motor[1][1] = 0
motor[1][2] = 1
motor[1][3] = 2
motor[2] = {}
motor[2][1] = 3
motor[2][2] = 4
motor[2][3] = 5
for i,m in ipairs(motor) do
for i,g in ipairs(m) do
gpio.mode(g, gpio.OUTPUT)
gpio.write(g, 1)
end
end
function motor_dir(m, dir)
if dir ~= 0 then
gpio.write(motor[m][3], 1)
gpio.write(motor[m][1], (1-dir)/2)
gpio.write(motor[m][2], (1+dir)/2)
else
gpio.write(motor[m][3], 0)
end
end
Peer = {}
function Peer:create(sck)
local peer = {}
setmetatable(peer, Peer)
peer.buffer = {}
return peer
end
function Peer:receive(sck, data)
self.buffer = self.buffer .. data
if #self.buffer >= 4 then
sck:close()
end
end
function(conn)
peer = Peer:create(conn)
conn:on("receive", peer:receive)
end

View File

@ -0,0 +1,12 @@
# flashing firmware onto NodeMCU
esptool.py --port /dev/ttyUSB0 write_flash -fm qio 0x00000 nodemcu-master-9-modules-2019-04-08-19-43-38-float.bin
# connecting to NodeMCU via serial terminal
cu -l /dev/ttyUSB0 -s 115200 dir
# uploading code to NodeMCU
nodemcu-uploader upload motor.lua
nodemcu-uploader upload init.lua
# sending data over wifi via socket
nc 192.168.4.1 80

View File

@ -0,0 +1 @@
cu -l /dev/ttyUSB0 -s 115200 dir

View File

@ -0,0 +1,2 @@
nodemcu-uploader upload motor.lua
nodemcu-uploader upload init.lua