Week 12: Input Devices

The inputs were chosen because I was thinking about the systems that I want to use inside my final project. I decided to test the potentiometer because it is a good indication of how resistors work to change the voltage, and this can be transferred easily into a lesson that teaches electronics. And also a Sonar since it is one of the most basic sensors out there in the field of robotics and also has a very easy to follow concept, pretty good for teaching lessons.

Potentiometer sensing

The potentiometer is pretty straightforward, you basically move a knob (or wiper) that allows you to change the value of the inside resistance of the component. 

Again, I used my Mandy Xiao for these trials and connected the potentiometer to one of the general purpose pin sections.

This time, I tried to use the Arduino IDE as a coding language, as after I finished with the machine week, I realized this is a more widespread language and has way more support for components. Also, the serial monitor is easier to set up for reading analog values than a system print like I was doing in micropython. 

My first tests were with the serial monitor, to see how precise my potentiometer was. Thanks to the analog channel of the XIAO actually the readings were very fine and with changes ranging between 2 to 3 with minimal movement. This is super cool.

The code was pretty simple, and I used an example that was already in Arduino, just adding the section for the visualization in the serial. 

I know the potentiometer is a pretty easy sensor to work with, coding it is also pretty straightforward but I feel it is a good application for what I need to do in my project.

After seeing that the code worked pretty seamlessly I wanted to use my display to show the voltage that was being read in the analog input. I asked ChatGPT to help me with this, and this conversation besides allowing me to see that there is a way easier way to program the ILI9341 with Arduino, helped me realize that my sensing can be affected by the 5V I was using, and not only that but it can also end up breaking the XIAO completely. I changed the pin situation for this time, but I realize that I will have to change my board over the next weeks for it to work properly with either 5V sensors and 3V3 ones. I will investigate this further for my FP board which will have the raspberry pi pico as a main microcontroller. 

In any case, I used the code provided by ChatGPT to test the TFT display, and it worked super well. I made some adjustments for a nicer viewing (changed the size of the voltage and put the value in another line).

Video of it working here


Sonar HC-SR04 

After that I wanted to test the sonar, I used the HC-SR04 ultrasonic sensor for this. I asked ChatGPT for some guidance to help me see a bar like sensing in my display, and I also used the serial monitor to check if the display was working as intended too.

According to the datasheet , the sensor works with 5V, but my XIAO readings have to be in 3V3, so I kinda went around it by feeding the sensor only with that amount of energy to see what happened. It kinda worked? I will surely need a voltage divider in the echo pin that is the input for it to be more stable than it was, but still I could see the sensing as intended. Only that the jumps between values were not fine and also not exact.

Hope the Xiao is ok as well after this little testing XD


Videos of the hcr working


Reviewing and Thoughts

I also helped some of my classmates with their sensors, one of them used an IR sensor, and I learned how a little remote control works with it. We debugged his code together which helped me learn a bit about it too. 

These weeks have been pretty hard because of things outside of my control which has made me lower my expectations into what I can achieve each week. This assignment, I truly was pretty simple with my testing.

I would love to test a light sensor too since it also is very widespread in robotics. Will add this if I end up using it for my FP.



Next Class

Molding and Casting