MAKER PI RP2040 Robot With IR-Control

by tonygo2 in Circuits > Microcontrollers

3078 Views, 7 Favorites, 0 Comments

MAKER PI RP2040 Robot With IR-Control

CY Robot-6.jpg

Cytron in Malaysia have just brought out another high quality and remarkably inexpensive Raspberry Pi RP2040 board. This one is as aimed at novice robot builders and is once again packed with features. It can control a pair of DC motors or a stepper motor and four servos. It has a loud piezo buzzer speaker, with silencing switch, on/off switch, 7 Grove connection sockets, 2 Neopixels, 13 status LEDs, 2 user buttons, a run/reset button, 4 motor test buttons and can be powered by DC batteries, a Lipo battery (with charging circuit) or via the USB cable. 4 Grove cables and a screwdriver for the terminals are supplied in the neat delivery box. (Full details here: Maker Pi RP2040 : Simplifying Robotics with Raspberry Pi® RP2040 (cytron.io) with international suppliers – ThePiHut.com in UK - only £9!)

The board came ready loaded with CircuitPython and an example program to demonstrate turning DC motors, moving servos, flashing the LEDs and Neopixels, playing a tune as the buttons were pressed. Save and printout this program as it very useful for reference.

I paired the Cytron board with an Adafruit Mini 3-Layer Round Robot Chassis Kit - 2WD with DC Motors and an Infra-Red remote kit bought on Ebay (remote, IR sensor, IR LED and cable).

Assemble the Chassis

chassis.jpg
CY Robot-7.jpg

There are no instructions with the neatly packaged chassis but it is easy to assemble if you lay out all the parts in a logical manner before you start. I had to gently file a couple of the tongues to get them to fit neatly into their slots.

There are plenty of holes to fit extra components but I’ve found that they seldom line up with holes in the bigger boards you try to attach. I used Blu Tack to fit the battery box (4xAA) to the top layer and then the microcontroller board on the top. Worked well, enough grip and very easy to adjust/remove as you modify your design and add more components.

I suggest you make a small cardboard ‘lift’ to hold the wheels off the table top while you program and test your setup.

A Good Look at the Board - Plenty of Components and Information

CY Robot-2.jpg
CY Robot-3.jpg

Power wires from the 4AA sized battery box were connected to the green screw terminals and the wires from the motors went to the black screw terminals, using the screwdriver included in the neat box. I then sat the assembled robot on the cardboard lift, to keep the wheels off the table top, connected the board to my computer running the Mu editor with a USB cable, switched on the power and ran the example program. Pressing the user and motor buttons confirmed that the wheels could turn.

Basic Robot Program - Part 1

basic 1-29.jpg

This imports the the necessary libraries, sets up the motors and defines routines to move the robot forward, backwards spin left and stop.

Basic Robot Program - Part 2

basic 30-58.jpg
New floor robot

This part defines a right spin and turns to the left and right about stationary wheel.

The final section calls each of these actions in turn to carry out a basic test.

The video shows a test of the floor robot demonstrating the seven different actions.

If you try this, and I hope you do, but find the motors move in the opposite direction just swap over the wires at the black terminal.

That Worked OK So It Is Now Time to Investigate IR-communication

I want the robot to respond to buttons pressed on the remote. I need buttons to STOP the robot from moving, to HALT the program and instruct it to move in six different ways: Forwards, backwards, turn and spin to left and right. I would also like feedback, via the Neopixels if the codes sent are being received and decoded correctly.

Investigating the Infra Red System

CY Robot-1.jpg

Adafruit supply an irremote library and some example code.(adafruit_irremote)

Go to circuitpython.readthedocs.io and search for adafruit_irremote

I connected the IR sensor to GP5 via a Grove cable and Grove port 3 and ran the test program.

Each press of a remote button should provide a list of 4 numbers. I decided to use the 3rd number as the code.

Running the program provided these numbers to represent the keys.


The Codes From My Zapper

remoteCodes.jpg

I decided to use the following buttons on the remote to control the robot.

2 to Halt the program

UP to go forward

DOWN to go backwards

LEFT and RIGHT for spins

* and # for turns

OK for Stop

Fixing on the IR Sensor

CY Robot-4.jpg

I needed to have the face of the sensor pointing upwards so I attached it to Grove port 1 with some Blu Tack. (Very useful stuff!)

I then wrote a program to take button presses from the remote to carry out moves with the robot.

Final Program - Part 1

Final 1-29.jpg

This imports the libraries and sets up the motors and Neopixels.

The Neopixels are used to provide feedback each time a button press signal is picked up by the sensor. GREEN means a good decode, RED means a failed decode and BLUE a too short signal received. Three MAGENTA flashes signal the end of the program.

Final Program - Part 2

30-52.jpg

These are the motor control routines.

Final Program - Part 3

53-73.jpg

Sorting out and applying the code from the remote and a routine for the final magenta flashes.

Final Program - Part 4

74-94.jpg

The main loop: it receives signals from the remote and passes valid code to the action routine coded earlier.

Problem: Interference From the DC Motors

Robot Test

This shows the robot working and receiving commands from the IR_remote. Quite a few commands were missed. (I'm sorry for the movement in the video which I put down to having the zapper in my right hand, the phone in the left and having to keep switching my attention between the two.) I fear that sparking in the motors is making 'electronic noise' and upsetting the reception of clear codes from the zapper.

You can download the code here:

Partial Solution

CY Robot-5.jpg

This is a known problem with DC motors and you can read about it on the Pololu site.I soldered 0.1 µF ceramic capacitors across the terminals of the motors as shown in the picture and this helped reduce the problem.

Not a perfect solution but it did help.

There appears to be a few problems with this CP library at the moment. You can follow what is going on here:

https://github.com/adafruit/Adafruit_CircuitPython...