9. Mechanical Design, Machine Design¶
This week’s project was to design and build a machine that includes mechanism + actuation + automation + application in a group. Our group decided to make the Table cleaning robot. My individual contribution was electronics and programming, which I did with Adam Stone, our work can be found Here
Electronics considerations¶
The first thing I did was make a list of what had to be considered in terms of electronics. I came up with the following:
- What inputs will be used
- What outputs will be used, and will they be powerful enough to drive the robot
- How will sensors worked
- How will power be provided
- How will the motors be controlled accuratly
- How will devices communicate with each other
Creating a rough sketch of electronics¶
Taking these things into consideration, I created the following rough sketch for electronics in Fritzing, an online breadboard. Fritzing was easy to set up, after installing, all the parts I needed were already availible, so I dragged and clicked them, then wired components together and added notes with pinouts. This is what I first came up with:
For the microcontroller, I chose the raspberry pi Pico. This is because the RP2040 has two seperate I2C busses, which means that each sensor can be handled independently. Later on however, we switched to an arduino Uno. This is because it was compatible with the CNC shield, which made it easier to control the motors. To get both sensors to work, we had to reassign the I2c addresses, which I will explain below.
For outputs, the direction down and up the table will be controlled by stepper motors, this is because stepper motors are precise enough to stop as soon as a signal as sent, and won’t roll like DC motors. For the spinning rag, I chose a DC motor, because it is able to spin fast and does not need much torque.
For sensors, I chose 2 VL53L1X time of flight sensors, these sensors provide accurate distance information no matter what surface they are pointing at, and because they work with I2C, it is easy for them to communicate with the microcontroller.
For a basic interface, I chose a buzzer. I later changed this to two buttons to control the motion of the rag, and starting the DC motors to move across the table.
For motor control, I initially chose 5 L298n Motor drivers, as they are able to control speed, and direction of a motor. Later, we changed this to a CNC arduino shield, which provides more precise control for motions in the x, y, and z axis, and provides easy access to functions like an emergency stop.
For power, we first chose a 12v 9Mah NIAD battery, however, this caused constraints for the mechanical portion of the robot. So instead, we used a DC power supply to controll all the motors.
Using 2 sensors¶
After having a general plan for the electrical portion of the Robot, we first decided to try and get 2 of the ToF sensors working at the same time, since we had before. I worked with Adam Stone on this.
I2c and Addresses¶
Because I2c communicates with specific devices, each device is referenced by a specific address. However, these devices are the same for the same I2C devices. In the case of the project, the 2 VL53L1x sensors have the exact same address, since they are the same sensor, which means the microcontroller isn’t able to differentiate between the 2 signals. However, the VL53L1x’s have rewriteable I2C Addresses, so one sensor is able to have a different address than the other, making the microcontroller able to decipher the different signals.
Using 2 sensors- Wiring and coding¶
The wiring for 2 sensors is mostly the same for wiring one sensor, both can go to the same SDA and SCL pins, as long as they have different addresses. The key difference is that the sensors also have to be wired to an XShut pin, this overides the sensor from using it’s default address, and instead changes it to using the rewritten one. We used the following example code from the VL53L1X library:
/*
This example shows how to set up and read multiple VL53L1X sensors connected to
the same I2C bus. Each sensor needs to have its XSHUT pin connected to a
different Arduino pin, and you should change sensorCount and the xshutPins array
below to match your setup.
For more information, see ST's application note AN4846 ("Using multiple VL53L0X
in a single design"). The principles described there apply to the VL53L1X as
well.
*/
#include <Wire.h>
#include <VL53L1X.h>
// The number of sensors in your system.
const uint8_t sensorCount = 2;
// The Arduino pin connected to the XSHUT pin of each sensor.
const uint8_t xshutPins[sensorCount] = { 4, 5, 6 };
VL53L1X sensors[sensorCount];
void setup()
{
while (!Serial) {}
Serial.begin(115200);
Wire.begin();
Wire.setClock(400000); // use 400 kHz I2C
// Disable/reset all sensors by driving their XSHUT pins low.
for (uint8_t i = 0; i < sensorCount; i++)
{
pinMode(xshutPins[i], OUTPUT);
digitalWrite(xshutPins[i], LOW);
}
// Enable, initialize, and start each sensor, one by one.
for (uint8_t i = 0; i < sensorCount; i++)
{
// Stop driving this sensor's XSHUT low. This should allow the carrier
// board to pull it high. (We do NOT want to drive XSHUT high since it is
// not level shifted.) Then wait a bit for the sensor to start up.
pinMode(xshutPins[i], INPUT);
delay(10);
sensors[i].setTimeout(500);
if (!sensors[i].init())
{
Serial.print("Failed to detect and initialize sensor ");
Serial.println(i);
while (1);
}
// Each sensor must have its address changed to a unique value other than
// the default of 0x29 (except for the last one, which could be left at
// the default). To make it simple, we'll just count up from 0x2A.
sensors[i].setAddress(0x2A + i);
sensors[i].startContinuous(50);
}
}
void loop()
{
for (uint8_t i = 0; i < sensorCount; i++)
{
Serial.print(sensors[i].read());
if (sensors[i].timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.print('\t');
}
Serial.println();
}
When running this code, we at first had issues. Both of the sensors would work for a little, and then one would stop working, sending the message 0 TIMEOUT
. We later find out that this was due to us not filtering any of the signals. After we added resistors between SDA, SCL, and ground, it worked much better, he’s when we were able to get consistent results:
Putting it all together¶
After this, we assembled the components according to my wiring guide, other than the changes that I mentioned, and used Adam Stone’s Code, documented here. You can see our final project working on the group site.