Categories
Development

Blink LED with Blynk via USB port

Let’s write code on Arduino Uno

For this project you will need an Arduino Uno board, a way to program it and an application Blynk on your phone.

Initial code was just a regular Arduino code to see that I didn’t make a mistake. It is rather trivial with this project, but it is good to be consistent and really test the basic code, so you will know the code is working.

void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);  
}

Since we don’t have any wireless connection to the Arduino Uno we will be using USB connection for that.

After checking the documentation on the Blynk page we need to install the Blynk library first.

And we also need to create a button in the Blink project on the phone.

Open the Blynk app and click on “New Project”. The project name will be “Blink” since we are blinking the LED on the Arduino Uno board. From the CHOOSE DEVICE list select Arduino UNO and for connection type USB. Theme is not important.

When you finish clik CREATE button and the Auth token is sent to the mail address you used to register.

You can see in the documentation page regarding USB connection that you need to use some scripts. Depending on which operating system you are using the extension is .bat or .sh.

There is an error in the example on the above mentioned page in the command Blynk.begin: The command should be Blynk.begin(Serial, auth); and not Blynk.begin(auth, Serial);

The script to start on the computer is located in the directory called scripts inside the Blynk library directory. It is called blynk-ser.sh on Mac or Linux and blynk-ser.bat on the Windows machine.

I tested the script on Mac machine with an Arduino Uno copy (using CH340 driver) and latest operating system (Catalina).

When starting the script it offered me port /dev/tty.usbserial-1410 but running the script with that port I always got a Resource busy message.

After some searching on the internet I got nothing. I was sure there is a “problem” with socat code, but wasn’t sure what and why. Anyway after playing with only socat I found out that the device /dev/cu.wchusbserial1410 gets me somewhere, but only if I start the script as a root. So the command:

sudo ./blynk-ser.sh -c /dev/cu.wchusbserial1410

was a success.

Leave a Reply

Your email address will not be published. Required fields are marked *