Running some programs to generate data.


First, some background information on how data is transferred from the Arduino to your laptop or desktop computer where it is stored and processed.

Our Arduinos have too little memory to store much data, so data has to be transferred off the Arduino as it is collected. We need to run a program on your laptop or desktop to receive this data, and save it into files. This program is called putty-cga. It is modelled on putty, enabling users to see what messages the Arduino types out, and give it commands, but also has the additional ability to receive data and put it in a file.

The USB connection is too slow to send the amount of data we want to collect, so we need to compress the data before sending it, and then uncompress it after it is sent. We take advantage of the second core of the RP2040 to compress the data and manage the USB transfer.

Data compression makes data transfer a little complicated. Putty-cga saves the compressed data in files (xxxxxx.cmp are compressed files) as it arrives, and another program (uncompress-all) is used to uncompress it later.

The Arduino IDE is used to download programs to your Arduino. However, for programs that transfer data, putty-cga is used to receive that data. To do so, exit the Arduino IDE and run putty-cga. You can type commands such as g followed by ENTER to start the Arduino program doing stuff. Type x and then ENTER when you are done running that Arduino program, which causes putty-cga to write out any last files. Each data file is called f000n.cmp, and corresponding readable text is in f000n.txt. There is also a file putty-cga.files that list all the file names used. To uncompress the compressed files f000n.cmp, type uncompress-all, to create ascii data files f000n.dat.


For these programs, put the robot upside down, so the robot doesn't actually go anywhere, the wheels just spin in the air.

Make sure your battery is fully charged and on. Connect the USB cable between the Arduino Nano and your computer.


steps is a program to collect step data. Update the phase calibration by editing the lines:
left_encoder.setPhases( 0x580C7F );
right_encoder.setPhases( 0x442D64 );
Compile and load it using the Arduino IDE, and then run it by typing g to the Serial Monitor window. You will see the robot move the wheels forward and back 10 times, with the movements getting smaller and smaller, and a lot of numbers and strange symbols printed out on the screen. This is the compressed data left_encoder.setPhases( 0x580C7F ); right_encoder.setPhases( 0x442D64 ); that needs to be saved by the program putty-cga.

Maybe typing s will stop the Arduino program, or you can press the reset button on the back end of the board next to the red, black, and yellow rows of pins.


Since the Arduino IDE does not provide a way to save the numbers that are printed out, we have to use a terminal program like putty to capture the data. You have loaded the steps program into the Arduino already. Now run the program putty-cga in the folder putty-stuff. On Linux, I type:
cd putty-stuff
./putty-cga

If you did not kill the Arduino IDE, you get messages like:
Error 16 from open /dev/ttyACM0: Device or resource busy
Error 2 from open /dev/ttyACM1: No such file or directory
If things are working you see something like:
Opened /dev/ttyACM0
user_input thread started.
Type g ENTER to start the steps program.

The wheels should spin, and stuff should be typed out. The wheels are moved 10 times (5 times forwards and 5 times backwards). When it is done it types out:
Wrote f0004.txt
Type x ENTER to kill putty-cga. These data files have been written to the folder putty-stuff:
f0000.cmp f0001.cmp f0002.cmp f0003.cmp f0004.cmp
f0000.txt f0001.txt f0002.txt f0003.txt f0004.txt f0005.txt
putty-cga.files

Run the uncompress-all program to uncompress the xxx.cmp files into xxx.dat files. This creates the files:
f0000.dat f0001.dat f0002.dat f0003.dat f0004.dat
The xxx.dat files can be loaded into Matlab for analysis.