• Jack Chen

Pcomp Week 7

This week I did the Two Way Serial Communication Lab. The example lab used an accelerometer but any sensor with two outputs can work for the lab. I first tried the lab with an accelerometer but got inconsistent results on my serial monitor (interaction with accelerometer does not change the data in a recognizable way). The output pins on my accelerometer is also different than the ones shown in the lab example, so I am not sure if I was using the wrong combination of pins or if my accelerometer is not functioning properly (other than power and ground, the pins on my accelerometer are VCC,SDA,SCL and INT). After trying different pins on the accelerometer and the Arduino along with switching to different wires and replacing the accelerometer with an LED to make sure power is going through the circuit I still did not get good results on the Serial monitor, so I ended up using a joystick module for the lab.

The joystick runs on 5 Volts instead of my Arduino nano’s 3.3V, so I connected an external power for the joystick. The rest of the setup is the same as the lab example with the push button giving input to the Arduino.

controller with serial monitor from Jack on Vimeo.

After pasting the Arduino code which takes in data from the joystick and pushbutton divided by punctuation, I went on to set up the code on P5 editor. The main segment of the code is the same as the previous serial communication labs with an additional segment which sets up a port selection in the sketch to allow the selection of ports when running the sketch each time. Because I used a joystick module instead of an accelerometer, I modified the mapping of the data in the example P5 sketch to the range of the joystick input.

two way serial with p5 from Jack on Vimeo.

The remainder of the lab contains a code to improve the management of serial communication through handshake (wait until receiving an input before requesting and sending new data).

0 views0 comments

©2019 Zikang Chen 

Film making, videography, photography