9 Replies - 517 Views - Last Post: 16 July 2019 - 11:12 AM

#1 sayhello   User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 263
  • Joined: 12-November 17

RC Car with esp8266 and MicroPython - an approach with code

Posted 21 January 2019 - 07:48 AM

dear community,


[btw - this seems to be a true hardware question] If you think that this fits somewhere else - please set me straigtht!

i am starting a project - Arduino-izing Lego Technic - and now i need some ideas for a car / vehicle to choose.

This project starts out as a quest to find a way to combine ease of Lego Technic chassis building with cheap commodity electronics to motorize and remote control it. I am looking for a car / vehicle that is able to work for this. This could be a simple chassis too:

i am looking for a car / vehicle that is able to work for this. This could be a simple chassis too:

cf:
https://www.instruct...-Control-and-L/
https://www.hackster...unctions-ee0bfa
https://www.instruct...ntrolled-Car-1/



This should be a part of a robotics workshop and therefore I need a Lego-based platform for younger kids who grew up with Lego but cannot afford to spend hundreds of dollars to buy power functions,
Lego motors, IR remote, and EV3. Thanks to numerous examples on the net and several and Youtube tutorials on integrating Arduino with Lego,
I will try to start out with an interesting example.

starting point; the kids should be able to complete this project with a small budget and I hope to incorporate this into my robotics workshop in the future.

the main thing is: i need to have the rear axle to be attached to a single N20 motor to move the kart forward and reverse via a TB6612FNG motor driver.
Front steering can be controlled by an SG90 servo motor.


Remote control should be able to be accomplished by a cheap IR remote/receiver solution based on

a. Arduino
b. Zigbee
c. bluetooth

I understand that IR remote thing /(and the method ) is pretty hard part toimplement and learn about a remote control system so it was a perfect option for this car.

since this is just a proof-of-concept project and the design follows function - i need to have an idea


the main question is: which Lego car to choose?

what would you suggest?

Is This A Good Question/Topic? 0
  • +

Replies To: RC Car with esp8266 and MicroPython - an approach with code

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15337
  • View blog
  • Posts: 61,463
  • Joined: 12-June 08

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 21 January 2019 - 08:26 AM

Bugatti or Porsche!
Was This Post Helpful? 0
  • +
  • -

#3 sayhello   User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 263
  • Joined: 12-November 17

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 21 January 2019 - 10:58 AM

hello and good day dear modi 123

well i am trying to figure it out. guess that I'd try to use a car chassis - a truely simple as possible car. Guess that this would be a good choice.

This would achieve multiple goals:

- By using a vehicle with the least amount of complexity you can keep the price low.
- By avoiding unnecessary parts the students' attention will not be drawn from the main and top topic at hand, goal is to get them more inclined to listen and cooperate
if they are not wondering about or playing with the bucket lifting mechanism of 8071.

-The less parts included in the design, the less chances for something to go wrong so i schould choose a simple car.
- Some space is needed in order to mount the required hardware (motor, batteries, receiver, anything inbetween) and this space is best left open for easy access to inspect, explain, debug, repair, replace, etc.
- This approach would be great to upgrade the "final result", either functionally (adding lights, brakes, etc), aesthetically (building a great looking body), and what is mostin intersting for me. to enhacne the wohle thign electronically (adding additional subsystems) or mechanically (if you or the students wish to do so.

Therefore i think that i should go with building a simple steered front axle without suspension, a rear axle that is nothing more than an axle and two wheels.


guess i put all the pieces to a flat assembly.. What do you say!?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15337
  • View blog
  • Posts: 61,463
  • Joined: 12-June 08

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 21 January 2019 - 12:21 PM

Mock it up in stud.io . Plenty of moc sites that have plans too.
Was This Post Helpful? 0
  • +
  • -

#5 sayhello   User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 263
  • Joined: 12-November 17

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 21 January 2019 - 12:32 PM

dear Modi 123_1

many thanks for the reply - happy to hear from you.

I am glad that you encourage me. I will go ahead and pull back my sleeves.

BTW - this is such a great community. I really love it!!

Greetings
Say
Was This Post Helpful? 0
  • +
  • -

#6 sayhello   User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 263
  • Joined: 12-November 17

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 03 February 2019 - 01:16 PM

dear community


At the beginning of my story I have to say, that this was my first time to IOT topic - and to the ESP32 and 8266

I'm a complete beginner, but one thing I have is the desire to known new technologies.


A month ago my colleague make presentation about #esp8266 and I was impressed this small board. So I decided that I would like to known more about #esp8266 and similar stuff.

I use Micropython (http://micropython.org/download) it is a firmware for the #esp8266 boards. At the beginning i have to underestand how it works, but I have read allmost a ton of webpages and articles about it.


some ideas regarding the aims:


What is needed for the car: We need to meet some conditions with the RC-car.


We ......:


- have the car expect one command every second. If it does not receive one, it stops.
- We can of course use the connection type that fits our existing hardware or use-case best. Once we have decided that, the search for a good connection library starts.

well - if i want to go with some web-app or pc controlled thing, then i should choose TCP/IP / WIFI or bluetooth ( with ESP 32)

regarding the hardware:


firstly: I would say that i should not make use of an Uno and an esp-01 module. This makes life much more difficult.
i think that i should choose a Wemos Mini D1 or a nodeMCU board. This will be smaller, cheaper and easier to use.

secondly perhaps i should choose a less old-fashioned motor driver than the 298. These will work well with 3.3V circuits,
be more efficient and maybe use fewer pins (which may be important when using the Wemos/nodeMCU). What do you think about this idea.

thirdly i think that i have to go with MicroPython: - it is a pretty intersting approach to stick - working with ESP8266 or ESP32

btw regarding the use of MicroPython i have found an interesting approach here:

written by david golak:
https://hackaday.io/...ol-car-via-wifi
How to build RC Car with the esp8266.

see the code https://github.com/d.../master/main.py




import machine
import time
LED_PIN=15
led=machine.Pin(LED_PIN,machine.Pin.OUT)
led.off()
LIGHT_PIN_L=13
light_l=machine.Pin(LIGHT_PIN_L,machine.Pin.OUT)
light_l.off()
LIGHT_PIN_R=2
light_r=machine.Pin(LIGHT_PIN_R,machine.Pin.OUT)
light_r.off()
class engines:
def __init__(self, machine):
self.machine = machine
self.left_first_pin = 0
self.left_second_pin = 5
self.right_first_pin = 14
self.right_second_pin = 12
def forward(self, duty=1000):
self.stop()
e1=machine.PWM(self.machine.Pin(self.left_first_pin),freq=100,duty=duty)
e2=machine.PWM(self.machine.Pin(self.right_first_pin),freq=100,duty=duty)
def backward(self, duty=1000):
self.stop()
e1=machine.PWM(self.machine.Pin(self.left_second_pin),freq=100,duty=duty)
e2=machine.PWM(self.machine.Pin(self.right_second_pin),freq=100,duty=duty)
def left_up(self):
self.stop()
e1=machine.PWM(self.machine.Pin(self.left_first_pin), freq=100, duty=400)
e2=machine.PWM(machine.Pin(self.right_first_pin), freq=100, duty=1000)
def right_up(self):
self.stop()
e1=machine.PWM(self.machine.Pin(self.left_first_pin),freq=100,duty=1000)
e2=machine.PWM(self.machine.Pin(self.right_first_pin),freq=100,duty=400)
def left_down(self):
self.stop()
e1=machine.PWM(self.machine.Pin(self.left_second_pin), freq=100, duty=400)
e2=machine.PWM(machine.Pin(self.right_second_pin), freq=100, duty=1000)
def right_down(self):
self.stop()
e1=machine.PWM(self.machine.Pin(self.left_second_pin),freq=100,duty=1000)
e2=machine.PWM(self.machine.Pin(self.right_second_pin),freq=100,duty=400)
def stop(self):
machine.PWM(self.machine.Pin(self.left_first_pin),freq=0,duty=0)
machine.PWM(self.machine.Pin(self.right_second_pin),freq=0,duty=0)
machine.PWM(self.machine.Pin(self.left_second_pin),freq=0,duty=0)
machine.PWM(self.machine.Pin(self.right_first_pin),freq=0,duty=0)
E=engines(machine)
try:
import usocket as socket
except:
import socket
CONTENT = b"""\
HTTP/1.0 200 OK
Hello #%d
"""
CONTENT = b"""\
HTTP/1.0 200 OK
Content-Type: text/html\n\r
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8">
</script>
<head>
<script type="text/javascript">
var DEVICE_URL = 'http://%s'
function iotAction(action){
if(action=='change_led'){
if(document.getElementById('led_value').value==1){
action='led_off'
document.getElementById('led_value').value=0
document.getElementById('led_control').style.backgroundImage="url('https://raw.githubusercontent.com/dgolak/esp8266/master/images/alarm_off.jpg')"
}else if(document.getElementById('led_value').value==0){
action='led_on'
document.getElementById('led_value').value=1
document.getElementById('led_control').style.backgroundImage="url('https://raw.githubusercontent.com/dgolak/esp8266/master/images/alarm_on.jpg')"
}else{
action="led_on"
}
}
if(action=='change_light'){
if(document.getElementById('light_value').value==1){
action='light_off'
document.getElementById('light_value').value=0
document.getElementById('light_control').style.backgroundImage="url('https://raw.githubusercontent.com/dgolak/esp8266/master/images/light_off.jpg')"
}else if(document.getElementById('light_value').value==0){
action='light_on'
document.getElementById('light_value').value=1
document.getElementById('light_control').style.backgroundImage="url('https://raw.githubusercontent.com/dgolak/esp8266/master/images/light_on.jpg')"
}else{
action="light_on"
}
}
var requestURL = DEVICE_URL + "/?action="+action
$.get (requestURL)
}
</script>
<style>
#container{
width:800px;
height:1300px;
background-image:url("https://raw.githubusercontent.com/dgolak/esp8266/master/images/navi2.png");
background-position:40px 110px;
background-size:720px;
background-repeat: no-repeat;
-webkit-user-select: none;
padding-top:100px;
}
button{
background-color:transparent;
border-color:transparent;
border:0px solid red
}
</style>
</head>
<center>
<div id="container">
<table cellpadding="0" cellspacing="0">
<tr>
<td style="padding-left:130px;" colspan="3">
<button style="width:440px;height:150px" ontouchstart="iotAction('forward')" ontouchend="iotAction('stop')"/>
</td>
</tr>
<tr>
<td><button style="width:180px;height:190px" ontouchstart="iotAction('left_up')" ontouchend="iotAction('stop')"/></td>
<td rowspan="2"><button style="width:350px;height:370px" ontouchstart="iotAction('stop')" ontouchend="iotAction('stop')"/></td>
<td><button style="width:180px;height:190px" ontouchstart="iotAction('right_up')" ontouchend="iotAction('stop')"/></td>
</tr>
<tr>
<td><button style="width:180px;height:220px" ontouchstart="iotAction('left_down')" ontouchend="iotAction('stop')"/></td>
<td><button style="width:180px;height:220px" ontouchstart="iotAction('right_down')" ontouchend="iotAction('stop')"/></td>
</tr>
<tr>
<td style="padding-left:130px;" colspan="3">
<button style="width:440px;height:150px" ontouchstart="iotAction('backward')" ontouchend="iotAction('stop')"/>
</td>
</tr>
</table>
<br/><br/>
<table>
<tr>
<td>
<input type="hidden" id="light_value" value="0"/>
<button id="light_control" style="width:200px;height:200px;background-image:url('https://raw.githubusercontent.com/dgolak/esp8266/master/images/light_off.jpg');background-size:200px;"" ontouchstart="iotAction('change_light')"></button>
</td>
<td>
<input type="hidden" id="led_value" value="0"/>
<button id="led_control" style="margin-left:20px;width:200px;height:200px;background-image:url('https://raw.githubusercontent.com/dgolak/esp8266/master/images/%s');background-size:200px;"" ontouchstart="iotAction('change_led')"></button>
</td>
</tr>
</table>
</div>
</center>
</html>
"""

def main(E,micropython_optimize=False):
s = socket.socket()
ai = socket.getaddrinfo("172.20.10.10", 80)
addr = ai[0][-1]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(5)
while True:
res = s.accept()
client_sock=res[0]
if not micropython_optimize:
client_stream = client_sock.makefile("rwb")
else:
client_stream = client_sock
req = client_stream.readline()
get = req.split()[1].decode('utf-8')
if get == '/?action=forward':
E.forward()
elif get == '/?action=left_up':
E.left_up()
elif get == '/?action=right_up':
E.right_up()
elif get == '/?action=left_down':
E.left_down()
elif get == '/?action=right_down':
E.right_down()
elif get == '/?action=backward':
E.backward()
elif get == '/?action=stop':
E.stop()
elif get == '/?action=led_on':
led.on()
elif get == '/?action=led_off':
led.off()
elif get == '/?action=light_on':
light_l.on()
light_r.on()
elif get == '/?action=light_off':
light_l.off()
light_r.off()
else:
pass
while True:
h = client_stream.readline()
if h == b"" or h == b"\r\n":
break
if led.value() == 1:
led_icon="alarm_on.jpg"
else:
led_icon = "alarm_off.jpg"
client_stream.write(CONTENT % (wlan.ifconfig()[0],led_icon))
client_stream.close()
if not micropython_optimize:
client_sock.close()
main(E)

[Click and drag to move]


see https://github.com/d.../master/main.py


well i guess that this is a straingthforward approach...

cf: david golak:
https://hackaday.io/...ol-car-via-wifi
How to build RC Car with the esp8266.

btw: my car has got a option of a steering axle - in other words - i have a slightly different car - than David has.
But that i think does not make a big difference.. I have to change the code at some places to fit.

i will have a closer look at this.


regards
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15337
  • View blog
  • Posts: 61,463
  • Joined: 12-June 08

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 03 February 2019 - 01:20 PM

If you want to have a blog post then please use the blog section.
Was This Post Helpful? 0
  • +
  • -

#8 sayhello   User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 263
  • Joined: 12-November 17

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 16 July 2019 - 10:05 AM

hello dear Dreamincode - experts


btw: hope i post this into the right forum / sup-Forum. If not - /(that means if i have not found /choosen the right one please set me straight. Many many thanks!

I am starting a project - Arduino-izing LEGO Technic - and now I need some ideas for a car / vehicle to choose. This project starts out as a quest to find a way to combine the ease of LEGO Technic chassis building with cheap commodity electronics to motorize and remote control it. 

I was looking for a vehicle that is able to work for this. This could be a simple chassis: https://www.instruct...-Control-and-L/ https://www.hackster...unctions-ee0bfa https://www.instruct...


This should be a part of a robotics workshop and therefore I need a LEGO-based platform for younger kids who grew up with Lego but cannot afford to spend hundreds of dollars to buy power functions, LEGO motors, IR remote, and EV3. Thanks to numerous examples on the net and several and Youtube tutorials on integrating Arduino with LEGO, I will try to start out with an interesting example. Starting point: the kids should be able to complete this project with a small budget and I hope to incorporate this into my robotics workshop in the future. The main thing is, I need to have the rear axle to be attached to a single N20 motor to move the kart forward and reverse via a TB6612FNG motor driver. Front steering can be controlled by an SG90 servo motor.

i have chosen the Lego Service Truck 8071 - see here:  https://www.lego.com/de-de/service/buildinginstructions/search?initialsearch=8071&ignorereferer=true#?text=8071

Remote control should be able to be accomplished by a cheap IR remote/receiver solution based on
Arduino
Zigbee
Bluetooth
or use the WEMOS ESP8266 of course

I understand that the IR remote hardware (and the method) is pretty hard part to implement and learn about a remote control system so it was a perfect option for this car.

Since this is just a proof-of-concept project and the design follows function - I need to have an idea. The main question is: How about LEGO Technic-8071 - the Service Truck? 


i have chosen the Lego Service Truck 8071 - see here:  https://www.lego.com/de-de/service/buildinginstructions/search?initialsearch=8071&ignorereferer=true#?text=8071


guess that i can add the steering and motor with ease 


Question: where you would attach the motors !? 


love to hear from you

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image

This post has been edited by sayhello: 16 July 2019 - 10:08 AM

Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15337
  • View blog
  • Posts: 61,463
  • Joined: 12-June 08

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 16 July 2019 - 10:49 AM

There is no project, yet, that you are sharing.

Moving to 'software dev'.

You also have an existing ramble on this. Merging.

This post has been edited by modi123_1: 16 July 2019 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15337
  • View blog
  • Posts: 61,463
  • Joined: 12-June 08

Re: RC Car with esp8266 and MicroPython - an approach with code

Posted 16 July 2019 - 11:12 AM

Side note - why not just make a legoized 'boebot'? It's a proven chassis design that is small, holds what it needs, and is expandable.

https://www.homescie...able-robot-kit/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1