Home About Me Weekly Assigments Final Project


Interface and Application Programming

Fab Academy 2018


Week #12

This week we have learned how we could 'talk' with an Arduino board trough laptop's USB port. There are many languages and softwares to use this week and I confused with which should I start!. Processing was my first decision.



Processing

Processing processing2-logo is a software which we could design a Graphical User Interface GUI application and connect them to control Arduino and other MCU throw serial.

Acctully before starting with Processing I should have an Arduino code deals with serial monitor successfuly. I used RGB LED in OUTPUT week so I have a good idea how every thing works so I just wrote a could which lights in red color when I just type 'r' in serial monitor window and send it to the Arduino also will lights in green, blue and in random colors.

This is my code


RGBcode

The previous code in exactly the same code I controlled using Processing software. At the beginning, it was somehow hard for me to deal with this software. Firstly I added the Serial library to be able to take with Arduino through serial port.


serialL

I decided to use buttons in my interfacing screen so after a little search I found that I should add a library called controlP5. I downloaded it from HERE> After that I unzipped it, then move the folder to libraries folder in processing download location. Then the library will appear in the list shown:


controlP5

After adding libraries I start playing with simple instructions and see the effect of them such as shown:


proTry

Finaly, I founded my favorite color then I added a title and control its font, color and size as shown:


proTry2

Now add a first button as shown:


proTry3

Now write code to connect the RED button with COM3 after connecting the Arduino to the laptop and uploading the previous mentioned code to it.


proTry4

I repeated the same instructions for the rest buttons. This how my final GUI window and code looks like


proGUI

Thanks to GOD everything is working perfectly. Watch the video




Processing With ATtiny 44 input Board



After I make sure everything was working with the commercial Arduino board, Now I should work with the board I designed in Input devices Week. This board had ATtiny44 microcntroller. Fortunately, No need for any change in Processing code, but with Arduino code when I tried to use it, I discovered that ATtiny didn't have any hardware serial pin on it!! so it gives an error while compiling the code. To solve that problem I used a software serial library and defined pin 0 , pin 1 as RX and TX pins. To connect RGB LED to my board I used the digital pin I designed for servo and Ultrasonic sensor. This is the connection :


attiny

But also I had another problem how to connect my board to the computer USB COM to send data to the board?. I solved that problem by using Arduino UNO board as USB to TTL convertor through this connection :


attinyTTL

This how overall wireing connction looks like:


atconn1
ATcon2

This is the modified code after adding software serial instead of serial and changing pin numbers:


Atcode1
ATcode2

The results in this video:








Using Blynk Application



I was in my room and I haven't any wireless module (WIFI or BLUETOOTH) to connect it to Arduino in order to be able to control it with my phone. So I searched for an application let me use USB serial port. Hopefully I found Blynk Blynkicon which is a very useful and cute Android application through it, I could control Arduino and many other MCU using my smart phone WITH and WITHOUT using wireless modules.
Firstly I carefully followed this video to connect my Arduino with my phone with USB Without any extra shields. I started by downloading the App freely from Play Store.

To add a new project I asked to choose my board and the connection type I selected them as shown:


b1

Then I have a list of components. Firstly I tried with a LED and connected it successfully and controlled it with my phone. To not repeat the procedure I will just document my work with Ultrasonic sensor. I chose the LCD to display the distance measurement. Then I selected the mode to control it and also the pin connect it (it is a virtual pin I will use it in the code to send data to serial port). This is the whole LCD settings


b2 b3 b4

The is the final result after finishing at my phone!. Nothing alive ! Nothing happens !!.


b5

After creating my new project I received an email with a code called Auth Token I will use it later. Now I should move to Arduino settings. First, I downloaded Blynk library from HERE unzipped the folder and added it to Arduino libraries folder. After that I visit This site to find the example code which will control the project on my phone. This is the code from the website.


blynk1

After copying the example to Arduino IDE I added Auth Token to it, then I have these two codes one which I made during Input week and the example I just copied from the website:


blynk3

Now I combined the two codes to have this final one, compiled it successfully which I uploaded it to my Arduino board


blynk4 blynk5

Now move to terminal to connect Arduino on COM3 to internet , go to Blynk library location and write this command blynk-ser.bat -c COM3 and see the results in terminal:


blynk2

Finally, I moved to my phone see some text on LCD. Then I moved my hand in front of the ultrasonic sensor and the distance was changed correctly!! Every thing works :) I was soooooo hapy.
You can watch the video.

Problems and difficulties

Problems in Python

Try a lot to install Pyserial library but there are many erorrs


nohope1 nohope2 nohope3
pyerror