Arduino over Raspberry Pi

I am trying to run Blynk on an Arduino, hooked up to a Raspberry Pi. I want to use it to control a RGB led strip, but the Raspberry Pi only has one pwm pin. I have uploaded the sketch to the Arduino, but I cannot get the Pi to run ./blynk-ser.sh.

pi@raspberrypi ~/blynk-library/scripts $ sudo ./blynk-ser.sh
[ Press Ctrl+C to exit ]
Can’t detect OS type!
pi@raspberrypi ~/blynk-library/scripts $

It was saying something about socat utility, so I ran sudo apt-get install socat, and it went through normally.

How can I get the server script to run on my Pi?

Actually this should work.
I can’t check it right now, but I filed a bug for that.

Till then, try disabling the check if platform inside of the script…

I have commented out where I think the problem was, now it gives a different result:

pi@raspberrypi ~/blynk-library/scripts $ sudo ./blynk-ser.sh
[ Press Ctrl+C to exit ]
Resetting device /dev/ttyUSB0…
Connecting: <-> openssl-connect:cloud.blynk.cc:8441,cafile=/home/pi/blynk-library/scripts/certs/server.crt,nodelay
2015/07/13 17:59:50 socat[9216] E exactly 2 addresses required (there are 1); use option “-h” for help
2015/07/13 17:59:50 socat[9216] N exit(1)
Reconnecting in 3s…
Connecting: <-> openssl-connect:cloud.blynk.cc:8441,cafile=/home/pi/blynk-library/scripts/certs/server.crt,nodelay
2015/07/13 17:59:53 socat[9219] E exactly 2 addresses required (there are 1); use option “-h” for help
2015/07/13 17:59:53 socat[9219] N exit(1)
Reconnecting in 3s…
^CExited!
pi@raspberrypi ~/blynk-library/scripts $

I am unsure of how to proceed from here.

OK, so I rechecked, and found another $OSType further down in the script, commented that out, and now it is working.

Thanks!

2 Likes

I am new to this and running into a similar problem trying to get an Arduino Mega with USB connection to a Raspberry Pi 2 to connect to Blynk. I follow instructions and only get the following on Terminal:

pi@raspi2 ~/sketchbook/libraries/Blynk/scripts $ sudo ./blynk-ser.sh
[ Press Ctrl+C to exit ]

Nothing else happens.

On which port is your Arduino located? It should be something like /dev/tty.usbblabla872.

You can enter the parameters with the script, for example

./blynk-ser.sh -p /dev/tty0 -b 9600 -s cloud.blynk.cc

Of course with correct parameters for your situation :slight_smile:

Thanks fro the quick reply. It is on port dev/tty/ACM0.

I have tried this with same result:

pi@raspi2 ~/sketchbook/libraries/Blynk/scripts $ sudo ./blynk-ser.sh -c /dev/ttyACM0 -b 9600 -s cloud.blynk.cc -p 8442
[ Press Ctrl+C to exit ]

Did you load up the appropriate sketch on your Arduino?

-edit-

I tied up my Arduino on my Pi and I get the same, weird, on my Macbook it worked fine last night.

@lfbaron did you modify the script as indicated by @Minocc?
The script is for pure linux and Mac’s. If you look through the script there are about 3 references to OSTYPE.

When I used USB on my Pi I changed the = “someosnamelikedarwinformacs” to != … and it worked fine.

If you have already done this let us know and we will advise further.

You are faboulus sir, I salute you.:

bastiaan@legotrainz:~/blynk-library/scripts $ sudo ./blynk-ser.sh
[ Press Ctrl+C to exit ]
/dev/tty.usbmodem not found.
Select serial port [ ]: /dev/ttyACM0
Resetting device /dev/ttyACM0...
stty: invalid argument '-f'
Try 'stty --help' for more information.
Warning: Server connection may be insecure!
Connecting: GOPEN:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,ixoff=0,ixon=0,ispeed=9600,ospeed=9600,crtscts=0 <-> TCP:192.168.0.25:8442,nodelay
2016/02/10 19:41:10 socat[26294] N opening character device "/dev/ttyACM0" for reading and writing
2016/02/10 19:41:10 socat[26294] N opening connection to AF=2 192.168.0.25:8442
2016/02/10 19:41:10 socat[26294] N successfully connected from local address AF=2 192.168.0.53:49631
2016/02/10 19:41:10 socat[26294] N starting data transfer loop with FDs [5,5] and [6,6]

Change every occurence in blynk-ser.sh of == “darwin” to != “darwin” (I think there three or four).

edit-

Actually, don’t do that, replace the “linux-gnu” with “linux-gnueabihf”, which is actually the OS type for the RasPi. My hardware was offline, but now it is online. Since RaspBian etc is more compatible with Linux than Mac (which is BSD), it actually works.

better still add the extra OS then the script will be good for linux, Mac and Pi :smile:

1 Like

Thanks both. I made the change and now get the following over and over:

Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> openssl-connect:cloud.blynk.cc:8442,cafile=/home/pi/sketchbook/libraries/Blynk/scripts/certs/server.crt,nodelay
2016/02/10 15:05:55 socat[3302] N opening character device “/dev/ttyACM0” for reading and writing
2016/02/10 15:05:55 socat[3302] N opening connection to AF=2 45.55.195.102:8442
2016/02/10 15:05:55 socat[3302] N successfully connected from local address AF=2 192.168.1.98:41319
2016/02/10 15:05:56 socat[3302] E SSL_connect(): socket closed by peer
2016/02/10 15:05:56 socat[3302] N exit(1)
Reconnecting in 3s…

I did upload the “Arduino Serial USB” sketch

There is, I think, one more change you need to make, in the top part of the file it says somewhere “TOTYPE=SSL”, change that to “TOTYPE=TCP”.

I don’t remember changing SSL to TCP but port 8442 is tcp for sure so reference to SSL does suggest a change is required. If it’s not this are you sure you have the Blynk token in your sketch?

I am positive I have the token in the sketch. Still get this:

Connecting: FILE:/dev/ttyACM0,raw,echo=0,clocal=1,cs8,nonblock=1,b9600 <-> TCP:cloud.blynk.cc:8442,nodelay
2016/02/10 15:36:44 socat[3525] N opening character device “/dev/ttyACM0” for reading and writing
2016/02/10 15:36:44 socat[3525] N opening connection to AF=2 45.55.195.102:8442
2016/02/10 15:36:45 socat[3525] N successfully connected from local address AF=2 192.168.1.98:41232
2016/02/10 15:36:45 socat[3525] N starting data transfer loop with FDs [3,3] and [4,4]
2016/02/10 15:36:45 socat[3525] E read(3, 0x19ae778, 8192): Resource temporarily unavailable
2016/02/10 15:36:45 socat[3525] N exit(1)

Sorry to be a pest. I setup an Arduino Uno with an ethernet shield without issues. This is different.

Also, when I run the script, Arduino IDE will timeout and will not upload script unless I reboot the Pi. Something about avrdude

Can you post the sketch?

/**************************************************************

  • Blynk is a platform with iOS and Android apps to control
  • Arduino, Raspberry Pi and the likes over the Internet.
  • You can easily build graphic interfaces for all your
  • projects by simply dragging and dropping widgets.
  • Downloads, docs, tutorials: http://www.blynk.cc
  • Blynk community: http://community.blynk.cc
  • Social networks: http://www.fb.com/blynkapp
  •                           http://twitter.com/blynk_app
    
  • Blynk library is licensed under MIT license
  • This example code is in public domain.

  • This example shows how to use ordinary Arduino Serial
  • to connect your project to Blynk.
  • Feel free to apply it to any other example. It’s simple!
    1. Optional, but recommended.
  • Connect additional USB-serial adapter to see the prints.
    1. Edit auth token and upload this sketch.
    1. Run the script (script located in “scripts” folder of library root,
  • e.g. ‘blynk-library/scripts’) for redirecting traffic to server:
  •  for Windows:
    
  •                 1. Open cmd.exe
    
  •                 2. write : (your way to blynk-ser.bat folder) example: "cd C:\blynk-library-0.3.1\blynk-library-0.3.1\scripts"
    
  •                 3. write : "blynk-ser.bat -c COM4" (where COM4 is port with your Arduino)
    
  •                 4. And press "Enter" , press "Enter" and press "Enter"
    
  •  for Linux and OSX:
    
  •                ./blynk-ser.sh (may need to run with sudo)
    
  • You can specify port, baud rate, and server endpoint like this:
  •  ./blynk-ser.sh -c <serial port> -b <baud rate> -s <server address> -p <server port>
    
  • For instance :
  •  ./blynk-ser.sh -c /dev/ttyACM0 -b 9600 -s cloud.blynk.cc -p 8442
    
  • Run blynk-ser.sh -h for more information
  • Be sure to select the right serial port (there may be multiple).
  • Attention!
  •    Arduino IDE may complain with "programmer is not responding".
    
  •    You need to terminate script before uploading new sketch.
    
    1. Start blynking! :slight_smile:

**************************************************************/

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3); // RX, TX
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “9107e9542b144af18db0xxxxxxxxxx”;

void setup()
{
SwSerial.begin(9600);
Blynk.begin(auth);
// Default baud rate is 9600. You could specify it like this:
//Blynk.begin(auth, 57600);
}

void loop()
{
Blynk.run();
}

I’m not sure about the software serial, this is my working sketch:

#include <BlynkSimpleSerial.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "blablabla";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth);
  // Default baud rate is 9600. You could specify it like this:
  //Blynk.begin(auth, 57600);
}

void loop()
{
  Blynk.run();
}

you could also try running the script with elevated rights, a.k.a. sudo ./blynk-ser.sh

That might help too

Software Serial gets a bad press, well it does in my book.

You will notice in the sample systems there is no Pi with USB, although it has been used by many. That is why the script has to be manually changed but also Software Serial wouldn’t really apply to the Pi.

I guess you could hook up the Arduino to the tx / rx pins on the Pi but most people are not doing that. You could also hook up the Software serial pins on the Arduino to a regular computer but this is all overkill.

Suggest you change your sketch to the one provided by @Lichtsignaal. I don’t have mine handy so I can’t say what is in my sketch. Without Software Serial you don’t get any feedback from the Arduino other than what you are seeing in the script but once it is set up that should be enough.

I am still unable to connect via Raspberry.

I have changed the blink-ser.sh script line 10 from"SSL" to “TCP”. Replaced “linux-gnu” with “linux-gnueabihf” in 4 instances. Uploaded the sample script:

#include <BlynkSimpleSerial.h>

char auth[] = “9107e9542b144af18db0bfxxxxxxxxxxx”;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
}

void loop()
{
Blynk.run();
}
Anything else I should be changing to see if this works?