├── README.md ├── boot.py ├── images ├── 10.jpg ├── 100.jpg ├── 110.jpg ├── 120.jpg ├── 20.jpg ├── 30.jpg ├── 40.jpg ├── 50.jpg ├── 60.jpg ├── 65.jpg ├── 70.jpg ├── 75.jpg ├── 80.jpg ├── 90.jpg ├── alarm_off.jpg ├── alarm_on.jpg ├── light_off.jpg ├── light_on.jpg ├── navi2.png └── you-screen.png └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # How to build RC Car with the esp8266. # 2 | 3 | 4 | At the beginning my story I would like to say, that this was my first time to IOT topic. 5 | I'm a complete beginner, but one thing I have is the desire to known new technologies. 6 | 7 | A month ago my colleague make presentation about #esp8266 and I was impressed this small board. 8 | So I decided that I would like to known more about #esp8266 and similar stuff like #arduino. 9 | 10 | I use Micropython (http://micropython.org/download) it is a firmware for the #esp8266 boards. 11 | 12 | At the beginning I don't underestand how it works, but I have read a lot of webpages and articles about it. 13 | The first success when I could turn on and turn off Led :) 14 | Next I bought distance sensor, temperature and humidity sensor.... 15 | 16 | Next I bought the engine but I didn't know nothing about. 17 | So I bought two engines SG90. Unfortunately but it turned out, that it is only the servo engine :( 18 | 19 | Afterwards I was reading about engines and I bought two engines and motor shield (L298N) 20 | 21 | 22 | ### Together with my son (7years old) we used old lego car body and double sided tape :) ### 23 | 24 | ### In effect ? ### 25 | 26 | 27 | ### Then we used the battery 9V to power the motor. ### 28 | 29 | 30 | ### Putting all together: ### 31 | 32 | 33 | 34 | When it comes to steering and turning sideways I used trick. 35 | For example if I wanted turn left I used left engine 30% power and right engine 80-100% power. 36 | 37 | Next I connected red LED and two light green LED on the front of car 38 | 39 | ### Everything works fine in python console. ### 40 | For instance, when I wanted to run I typed ** E.forward() ** 41 | when I wanted to stop car I had to type ** E.stop(). ** 42 | 43 | ### Python code is on my github (please give me a star :) ): ### 44 | https://github.com/dgolak/esp8266/blob/master/main.py 45 | Afterwards I wrote wifi connection to my mobile phone, simple webserwer and web application to steering a car. 46 | 47 | ### Putting all together: ### 48 | 49 | 50 | 51 | ### To sum up. ### 52 | It was a great time with my son, we made a simple car with the steering by mobile phone or any devices with the use of WIFI 53 | 54 | [![Youtube](https://github.com/dgolak/esp8266/blob/master/images/you-screen.png)](https://youtu.be/-qwm66QJIss) 55 | -------------------------------------------------------------------------------- /boot.py: -------------------------------------------------------------------------------- 1 | import esp 2 | #esp.osdebug(None) 3 | import gc 4 | import network 5 | 6 | #network connection 7 | wlan = network.WLAN(network.STA_IF) 8 | wlan.active(True) 9 | wlan.connect('WIFI_NAME','WIFI_PASSWORD') 10 | ifcfg = wlan.ifconfig() 11 | 12 | #webrepl 13 | import webrepl 14 | webrepl.start() 15 | gc.collect() 16 | -------------------------------------------------------------------------------- /images/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/10.jpg -------------------------------------------------------------------------------- /images/100.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/100.jpg -------------------------------------------------------------------------------- /images/110.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/110.jpg -------------------------------------------------------------------------------- /images/120.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/120.jpg -------------------------------------------------------------------------------- /images/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/20.jpg -------------------------------------------------------------------------------- /images/30.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/30.jpg -------------------------------------------------------------------------------- /images/40.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/40.jpg -------------------------------------------------------------------------------- /images/50.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/50.jpg -------------------------------------------------------------------------------- /images/60.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/60.jpg -------------------------------------------------------------------------------- /images/65.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/65.jpg -------------------------------------------------------------------------------- /images/70.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/70.jpg -------------------------------------------------------------------------------- /images/75.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/75.jpg -------------------------------------------------------------------------------- /images/80.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/80.jpg -------------------------------------------------------------------------------- /images/90.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/90.jpg -------------------------------------------------------------------------------- /images/alarm_off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/alarm_off.jpg -------------------------------------------------------------------------------- /images/alarm_on.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/alarm_on.jpg -------------------------------------------------------------------------------- /images/light_off.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/light_off.jpg -------------------------------------------------------------------------------- /images/light_on.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/light_on.jpg -------------------------------------------------------------------------------- /images/navi2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/navi2.png -------------------------------------------------------------------------------- /images/you-screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dgolak/esp8266/66eb28a52d8f6b281243aa906de2d2bfde5c437f/images/you-screen.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import machine 2 | import time 3 | LED_PIN=15 4 | led=machine.Pin(LED_PIN,machine.Pin.OUT) 5 | led.off() 6 | LIGHT_PIN_L=13 7 | light_l=machine.Pin(LIGHT_PIN_L,machine.Pin.OUT) 8 | light_l.off() 9 | LIGHT_PIN_R=2 10 | light_r=machine.Pin(LIGHT_PIN_R,machine.Pin.OUT) 11 | light_r.off() 12 | class engines: 13 | def __init__(self, machine): 14 | self.machine = machine 15 | self.left_first_pin = 0 16 | self.left_second_pin = 5 17 | self.right_first_pin = 14 18 | self.right_second_pin = 12 19 | def forward(self, duty=1000): 20 | self.stop() 21 | e1=machine.PWM(self.machine.Pin(self.left_first_pin),freq=100,duty=duty) 22 | e2=machine.PWM(self.machine.Pin(self.right_first_pin),freq=100,duty=duty) 23 | def backward(self, duty=1000): 24 | self.stop() 25 | e1=machine.PWM(self.machine.Pin(self.left_second_pin),freq=100,duty=duty) 26 | e2=machine.PWM(self.machine.Pin(self.right_second_pin),freq=100,duty=duty) 27 | def left_up(self): 28 | self.stop() 29 | e1=machine.PWM(self.machine.Pin(self.left_first_pin), freq=100, duty=400) 30 | e2=machine.PWM(machine.Pin(self.right_first_pin), freq=100, duty=1000) 31 | def right_up(self): 32 | self.stop() 33 | e1=machine.PWM(self.machine.Pin(self.left_first_pin),freq=100,duty=1000) 34 | e2=machine.PWM(self.machine.Pin(self.right_first_pin),freq=100,duty=400) 35 | def left_down(self): 36 | self.stop() 37 | e1=machine.PWM(self.machine.Pin(self.left_second_pin), freq=100, duty=400) 38 | e2=machine.PWM(machine.Pin(self.right_second_pin), freq=100, duty=1000) 39 | def right_down(self): 40 | self.stop() 41 | e1=machine.PWM(self.machine.Pin(self.left_second_pin),freq=100,duty=1000) 42 | e2=machine.PWM(self.machine.Pin(self.right_second_pin),freq=100,duty=400) 43 | def stop(self): 44 | machine.PWM(self.machine.Pin(self.left_first_pin),freq=0,duty=0) 45 | machine.PWM(self.machine.Pin(self.right_second_pin),freq=0,duty=0) 46 | machine.PWM(self.machine.Pin(self.left_second_pin),freq=0,duty=0) 47 | machine.PWM(self.machine.Pin(self.right_first_pin),freq=0,duty=0) 48 | E=engines(machine) 49 | try: 50 | import usocket as socket 51 | except: 52 | import socket 53 | CONTENT = b"""\ 54 | HTTP/1.0 200 OK 55 | Hello #%d 56 | """ 57 | CONTENT = b"""\ 58 | HTTP/1.0 200 OK 59 | Content-Type: text/html\n\r 60 | 61 | 63 | 64 | 97 | 114 | 115 |
116 |
117 | 118 | 119 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 136 | 137 |
120 |
134 |
138 |

139 | 140 | 141 | 145 | 149 | 150 |
142 | 143 | 144 | 146 | 147 | 148 |
151 |
152 |
153 | 154 | """ 155 | 156 | def main(E,micropython_optimize=False): 157 | s = socket.socket() 158 | ai = socket.getaddrinfo("172.20.10.10", 80) 159 | addr = ai[0][-1] 160 | s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 161 | s.bind(addr) 162 | s.listen(5) 163 | while True: 164 | res = s.accept() 165 | client_sock=res[0] 166 | if not micropython_optimize: 167 | client_stream = client_sock.makefile("rwb") 168 | else: 169 | client_stream = client_sock 170 | req = client_stream.readline() 171 | get = req.split()[1].decode('utf-8') 172 | if get == '/?action=forward': 173 | E.forward() 174 | elif get == '/?action=left_up': 175 | E.left_up() 176 | elif get == '/?action=right_up': 177 | E.right_up() 178 | elif get == '/?action=left_down': 179 | E.left_down() 180 | elif get == '/?action=right_down': 181 | E.right_down() 182 | elif get == '/?action=backward': 183 | E.backward() 184 | elif get == '/?action=stop': 185 | E.stop() 186 | elif get == '/?action=led_on': 187 | led.on() 188 | elif get == '/?action=led_off': 189 | led.off() 190 | elif get == '/?action=light_on': 191 | light_l.on() 192 | light_r.on() 193 | elif get == '/?action=light_off': 194 | light_l.off() 195 | light_r.off() 196 | else: 197 | pass 198 | while True: 199 | h = client_stream.readline() 200 | if h == b"" or h == b"\r\n": 201 | break 202 | if led.value() == 1: 203 | led_icon="alarm_on.jpg" 204 | else: 205 | led_icon = "alarm_off.jpg" 206 | client_stream.write(CONTENT % (wlan.ifconfig()[0],led_icon)) 207 | client_stream.close() 208 | if not micropython_optimize: 209 | client_sock.close() 210 | main(E) 211 | --------------------------------------------------------------------------------