Hello @Costas, thank you but this is more related to interface Arduino <-> Arduino, this interface I am able to do. But how could I modify the example below to receive the serial data from Arduino on the Raspberry USB port?
The port in raspberry is /dev/ttyACM0 which somehow needs to be declared?!
=/
// Blynk "gp" numbers are BCM numbers, so gp17 is physical pin 11
// #define BLYNK_DEBUG
#define BLYNK_PRINT stdout
#ifdef RASPBERRY
#include <BlynkApiWiringPi.h>
#else
#include <BlynkApiLinux.h>
#endif
#include <BlynkSocket.h>
#include <BlynkOptionsParser.h>
static BlynkTransportSocket _blynkTransport;
BlynkSocket Blynk(_blynkTransport);
#include <BlynkWidgets.h>
unsigned int uptime; // 1 second intervals
unsigned int pinStatus; // status of BCM 17
unsigned int lastpinStatus = 0; // to toggle
void myTimerEvent() // button widget on V0 or direct access gp17 button
{
uptime = (millis() / 1000);
Blynk.virtualWrite(V1, uptime);
pinStatus = digitalRead(17);
if(pinStatus != lastpinStatus){
lastpinStatus = pinStatus;
printf("GP17 pin status: %i\n", pinStatus);
if(pinStatus == 1){ // this is to synchronise V1 button if gp17 button is pressed
Blynk.virtualWrite(V0, 1);
}
else{
Blynk.virtualWrite(V0, 0);
}
}
}
void setup()
{
//nothing to go here yet
}
BLYNK_WRITE(V0) // button set at PUSH frequency
{
if(param[0] == 1){
printf("V1 turned device ON\n");
digitalWrite (17, HIGH) ;
}
else{
printf("V1 turned device OFF\n");
digitalWrite (17, LOW) ;
}
}
void loop()
{
Blynk.run();
if(millis() >= uptime + 1){ // 1 second intervals
myTimerEvent();
}
}
int main(int argc, char* argv[])
{
const char *auth, *serv;
uint16_t port;
parse_options(argc, argv, auth, serv, port);
Blynk.begin(auth, serv, port);
while(true) {
loop();
}
return 0;
}
Using NodeJS I am able to receive the data from Arduino, but, I am unable to allocate them on the Virtual Pins (So I believe its easier to try to make it work with C++ above):
const SerialPort = require(āserialportā);
const port = new SerialPort(ā/dev/ttyACM0ā, () => {
console.log(āPort Openedā);
});
const parsers = SerialPort.parsers;
const parser = new parsers.Readline({
delimiter: ā\nā
});
port.pipe(parser);
parser.on(ādataā, console.log);
I havenāt tested this yet, so there could be a syntax error or three⦠but I believe this should do the trick⦠using terminal, but any Display should work within display limits.
var term = new blynk.WidgetTerminal(13); // Setup Terminal Widget on vPin 13
const SerialPort = require(āserialportā);
const port = new SerialPort(ā/dev/ttyACM0ā, () => {
console.log(āPort Openedā);
});
const parsers = SerialPort.parsers;
const parser = new parsers.Readline({
delimiter: ā\nā
});
port.pipe(parser);
parser.on(ādataā, function(serdata));
term.write(serdata); // Send serial data to terminal on vPin 13
});
OK, got it⦠you are correct that it isnāt Blynk specific, (Hint, neither is this topic ) but I left a few links that should put you on track.
The same principle should work for this topic as well⦠parse your data stream out into individual components and send them to the App via Blynk.virtualWrite(vPin, value) However the precise parsing process with WireingPi might be different then true C++ on another Arduino/ESP.