Skip to content

rosmo-robot/micropython

Repository files navigation

micropython

Micropython code for Rosmo Robot

Very much a work in progress

Quick test:
copy the lot to your esp32 and then run this

from RosMo import RosMo
from time import sleep

rosmo = RosMo()
rosmo.car.forward(0.5)
sleep(1)
rosmo.car.stop()

Web UI

The web ui is NOT currently using encoders, because I can only get one encoder to accurately control speed at any given time. When I use all 4 the interrupts interact in some way and bollox the encoder readings

To try the webserver, copy everything to the esp32.

Edit secrets.py to give your wifi details.

run RosMo_WebServer.py - if you run it in Thonny you can get the ip for the web page.

7

going to that ip in your browser should show the control page

8

Autostart

If you would like RosMo_WebServer.py to start every time the robot is powered up then copy it to main.py

Encoder

To try encoder code with one motor

from RosMo_N20enc import EncodedMotor, PID
# Create a motor object
m1 = EncodedMotor(21, 39, False, 14, 9)  # Motor(fwd pin, bkwd pin, Reversed, encA, encB, frequency) Default frequency is set at 50Hz

# Create a PID object  with desired PID values
p1 = PID(m1, 3, 0, 10, 1000)  # PID(Motor object, Propotional, Derivative, Integral, Max correction speed)

while(1):
  p1.setRPM(180)

Ultrasonic HR-S04 sensor

There is code for an ultrasonic sensor in RosMo.py.
Below is rudimentary obstacle avoidance code with the sensor using pins 13 and 11

from RosMo import RosMo
from time import sleep
rosmo = RosMo()
rosmo.addUltrasonic(13,11)

while True:
    d = (rosmo.getDistanceCm() + rosmo.getDistanceCm() + rosmo.getDistanceCm() + rosmo.getDistanceCm() )/4
    print(d)
    if d < 10:
        rosmo.car.backward(0.4)
        sleep(0.2)
        rosmo.car.turn_right(0.8)
        sleep(0.4)
    else:
        rosmo.car.forward(0.6)
        sleep(0.5)

More sensors

Laser sensors & more

Notes on installing micropython on the esp32-s3 using windows

Open a cmd window and install esptool. In this example it was already installed

1

Look in device manager to find which comport the board is on (which was COM7 in my case not 36 as in illustration)

2

Erase the flash memory

3

Downloaded the latest bin from the micropython site

https://micropython.org/download/ESP32_GENERIC_S3/

4

Navigate to the directory containing the downloaded and run the command suggested in install instructions on the micropython site

5

Open Thonny and select configure interpreter.

6

Select MicroPython (ESP32)


Notes on installing micropython on the esp32-s3 using Ubuntu

sudo apt install pipx thonny

pipx ensurepath

pipx install esptool

Remove the Esp32s3 from the robot and connect to your computer

sudo dmesg | grep tty (note the bit after tty and make the line below match that)

esptool.py --chip esp32s3 --port /dev/ttyUSB0 erase_flash

Get the latest .bin file: https://micropython.org/download/ESP32_GENERIC_S3/

cd /Downloads (or wherever your downloads end up)

ls (to remind yourself what the file is called)

Flash the latest bin file: esptool.py --chip esp32s3 --port /dev/ttyUSB0 write_flash -z 0 [Name of the latest bin file]

About

Micropython code for Rosmo Robot

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages