Week 11. Interface and Application Programming

Week 11. Interface and Application Programming

2018, Nov 27    

Reference: Input Devices
OS: Linux
Software: Eagle, mods

For this week assignment, we have to make a software interface using an input or output device we made. I chose to make a new board with the ATtiny45 to gather data from the ultrasonic sensor HC-SR04. During the input week, I made the same board but with an ATtiny44. I did not manage to make that one work correctly, so making this new board based on Neil’s would allow me to double check my error and hopefully figure out what is wrong with my previous board.

Design and Fabrication

Since I made this board before with my own alteration using an ATtiny44 for Input Week, I decided to remake it just with the components that Neil did without adding extra (using ATtiny45).
I used Eagle to redesign the same ultrasonic sensor.

Diagram

Circuit

Board

Programming and Testing

Since I am using a Windows Machine, I used VMWare to access my linux partition. I cd into the directory with the files I downloaded from Input Devices.

I then ran the following line of code:

make -f hello.HC-SR04.make

This will output the hello.HC-SR04.out file. Then I connected the target board with the ATtiny45 to my USBTiny Programmer board. I powered the target board with the FTDI cable.

conection

Then I programmed the output file into the target board I just fabricated with the following line of code:

sudo make -f hello.HC-SR04.make program-usbtiny

I disconnected the programmer from my board and connected the target board again to make sure my computer is detecting it. For testing, I ran the python code provided by Neil by running the following line of code:

sudo python hello.HC-SR04.py /dev/ttyUSB0

This will read in the serial data coming from port /dev/ttyUSB0 and run the python code with the interface application.

ubuntu

test

2x speed up video of HC-SR04 interface test.

Programming using Arduino (wrong timing…)

I encountered a lot of problem with synchronization on the ATtiny when programmed with the Arduino UNO and Arduino IDE. Same problem I had with my previous board. This time, I burned the bootloader first and tested with programming at 1Mhz instead of 8MHz and it worked. It seems to be displaying the distance value correctly on the Arduino Serial Monitor reading the com port of the FTDI RX pin.

Here are some images of synchronization problem I had with the Attiny45. The baudrate I set was 9600, but on the serial monitor, it only showed “?????” ubuntu
I started playing with the baudrate on the serial monitor keeping the setup at 9600 and found that at 1200 it was working. That is a factor of 8 times slower. ubuntu

I initially set the clock to 8Mhz when those errors showed.

Here is the correct arduino setup with clock at 1Mhz:

ubuntu

Now it is working correctly. ubuntu

Processing - Interface

I used processing for creating a simple interface that displays the distance measured from the HC-SR04 from the Attiny45 through serial. Serial.print sends ASCII character so we can understand. Serial.write sends raw byte. We need to make sure we remember to process them accordingly. After some trial and error to figure out why the data was not read correctly on the processing side, I realized that the data is been sent way too fast for it to process, I added a delay of 100ms and it works. Not very fluid, but good enough.
Arduino Code
Processing Code

2x speed up video of HC-SR04 Processing interface test.