Interface and application programming
This week we will program our board to read a input and create an answer from the computer.
For this assignment I will use the sensor HC-SR04. I wanted to check this one before make a decision about which one to use on the final project. However, turn to infrared because can measure closer distances and this one can take longer and, on my case, it was necessary.
Before going through the assignment, it is important to stop and check the differences between Arduino and Processing. Even if they have similar IDE, there are also differences:
Anyway, it is possible to work with both of them and, once you get the knowledge can be funny to play with them.
The first try was a simple example where I just set a button to click and change the picture on the screen.
I used Processing to create the answer on the interface. To be able to communicate Arduino and Processing, take care of the port. Most of the setting you need you can find them on “Sketch” and if you want to get some examples you can find them on: “File/Examples”
Now, you are ready to program your board. In this case, I am using the sensor HCSR04 that will take a measure of distance and depend on which distance is, the interface will show one picture or another one.
This week I had problems communicating the two programs because I could not find the way. Also, when everything looked connected, it was always something missing between computers software or cables with some mistakes.
On the code you can read three different values because I tried at the beginning to reach three images, one on 0 holding the ball, another in +1 with the ball up and the last one on -1 taking the ball down. However, I just got two of them responding.
In this case I worked with MAC and, for that, I have to set the plugging to tell Arduino to give me the port of my board. (CH341SER_MAC)
After be messing around and do not get the result required, it was necessary to start all over again step by step. My ISP stop working so, I have to get another one, on the middle time, I decided to practice with Arduino UNO. connecting the sensor HCSR04 to the programmer GND, VCC 5v, Echo in Pin9 and Trig in Pin10.
At the first try I did not get any response for the code so, I write serial.println(“hello”) that means that on my code I need to change serial.write for serial.println to be able to see any response. Serial.write talks in binary so, we need the serial.println to convert this to ASCII text.
Checking the Processing code, I got an error on the port because I defined before for MAC and now with Windows I just need to write “COM3” instead of “/dev/cu.usbserial-FTHBOXCL”
The sensor was answering without any input so, I went to the Arduino code and I discover a delay (1000) that was interrupting the orders from the Processing code that says to change the images depend of the input he has. This hypothesis was wrong also, because when I delated the delay the images change even faster than before. So, what was the mistake? I read over the Arduino code and start to write it down for what I need each command and delete the ones that I am not using. Leave it in like this.
I check that work and go to Processing and did the same. So, the extra information and values that I was trying on the assignment before were deleted also, leaving the code like this.
Everything work with Arduino UNO but now, I need to test my own board. I do not have another board that I used on the first test so, I took my hello board, set up the code and MISTAKE. What was wrong now? The port was not there. We update the ISP driver and the FPDI on the computer, but nothing. Looking that it was impossible to program that board and I have the rest settles on the final project, the only thing I can do is design a new one.
On the video you can watch how the two programs speak to each other with Arduino UNO.
After go over everything again an again. My instructors and me found the mistake. First, on my Hello Board was one pin creating a bad conection because was almost free, it was just to set up good and solved the first problem. But the second one it was on the comunication between Arduino and Processing. They were not talking the same language.
At the end it was a matter of value, change from 0 to 1,2 or 3.
With everything set, it is time to check it:
Arduino and Processing.Click file
Arduino and Processing. Sensor HCSR04 file
Arduino and Processing. Arduino UNO sketch and Board Sketch.
C+language
Java language
HC-SR04 and Arduino
Processing sketch