
Attachinterrupt() The Quarantine Away
This project uses two encoders to control two servos through a Raspberry pi server and Arduino client. The two encoders were connected to the Arduino and used attachinterrupts() to interrupt the loop in the code to send the encoders' positions every time the encoder position was changed. This allowed for immediate movement of the servos without delay.
​
The project was done in collaboration with a teammate who was in charge of the hardware aspect. However, due to strict COVID-19 restrictions and low access to materials, we weren't able to add more to the servos besides plastic rods he found around his house.
​
From the software side, I was able to effectively have the Raspberry Pi server running through Flask and was able to have it efficiently communicate with the Arduino client. After port forwarding, my teammate was able to use his encoders and Arduino client in New Jersey to control my servos in North Carolina.
​
Here's a snippet of the client code:
Since this keyboard is small and I didn't plan on using more than five buttons, I decided to use MicroPython and Thonny. This would allow for rapid testing for both the code and circuit. ​

Fortunately, the Raspberry server code wasn't difficult and was pretty simple to set up using flask. In the moment of creating the code, I decided to split up the 180 degrees of the servo into 10 'states.' Instead of allowing the encoder position to map 1:1 with the servo. This would have required multiple encoders turns to move the servos.
​
For future iterations, I would choose a different way to map the encoders to the servos than the states I did here. I would have to brainstorm of a better way.

For the sake of presentation, this video shows my teammate controlling the servos with his encoders. Here, he is still controlling the servos using the Raspberry Pi servo and Arduino client.