imsyf
October 31, 2016, 3:43pm
1
I’m trying to send a value from one Arduino Uno board to another Arduino Uno board which both are connected to Blynk server via USB. But I can’t make it work, even for simple digital pin value. Here is the code that I use:
Sender - Uno A:
[code]
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3);
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>
char auth[] = “42d9928a261b4d008ed8c35d3068b7d9”;
WidgetBridge bridge1(V1);
SimpleTimer timer;
static bool value = true;
int ledPinA = 10;
int ledPinB = 12;
void blynkAnotherDevice(){
if(value){
digitalWrite(ledPinA, HIGH);
bridge1.digitalWrite(ledPinB, HIGH);
}
else{
digitalWrite(ledPinA, LOW);
bridge1.digitalWrite(ledPinB, LOW);
}
value = !value;
}
void setup(){
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(auth, Serial);
while(!Blynk.connect());
bridge1.setAuthToken(“779e3447c4914b6986852a31d65161d6”);
timer.setInterval(1000L, blynkAnotherDevice);
}
void loop(){
Blynk.run();
timer.run();
}[/code]
Receiver - Uno B:
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3);
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>
char auth[] = "779e3447c4914b6986852a31d65161d6";
void setup(){
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(auth, Serial);
while(!Blynk.connect());
}
void loop(){
Blynk.run();
}
Is there anything wrong about the code?
imsyf
October 31, 2016, 4:16pm
3
I did. I made a little modification from the example that you give due to my hardware limitation.
I suspect there is a different method to do bridge.setAuthToken()
if we connect the board to the internet via USB? Just like when we do Blynk.begin()
?
See the USB_Serial example. It contains a sketch, but it’s basically the same yes.
imsyf
October 31, 2016, 5:23pm
5
I tried it before I was doing all this. I managed to blink LED using Blynk app with the board connected to internet via USB.
What do you think about my code above? Is there anything you found suspicious to be the problem?
No, your code looks fine from here. Using the timer’s is the way go and loop() is clean, keep that up
imsyf
October 31, 2016, 5:27pm
7
But, still, it’s not working. Uno B’s Pin D12 stays LOW
eventhough Uno A asked it to be HIGH
.
On UNO A, try to add the function:
BLYNK_CONNECTED()
{
bridge1.setAuthToken("779e3447c4914b6986852a31d65161d6");
}
Above setup is fine, just like you would use BLYNK_WRITE, outside of any function(s).
imsyf
October 31, 2016, 5:44pm
9
Have done that. It’s still not working
imsyf
October 31, 2016, 6:44pm
10
God. This problem drives me crazy. I don’t know what’s wrong with it.
Dmitriy
October 31, 2016, 6:50pm
11
Don’t see anything strange. Please try to use virtual pins instead of digital. Does that work?
Dmitriy
October 31, 2016, 6:53pm
12
Just saw. YOu have different pin indexes in sketch 1 and sketch 2. IS that correct?
imsyf
October 31, 2016, 11:21pm
13
I did try using virtual pin, same thing happened.
I’m sorry, I’m kind of lost. What do you mean by pin indexes?
Dmitriy
October 31, 2016, 11:41pm
14
imsyf:
same thing happened.
Please post your code.
int ledPinA = 10;
int ledPinB = 12;
and
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
Dmitriy
October 31, 2016, 11:43pm
15
Also please post here debug output.
imsyf
November 1, 2016, 12:02am
16
Dmitriy:
int ledPinA = 10;
int ledPinB = 12;
and
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
Uno A’s ledPinA
is connected to a LED. I made it that way so I can see in what state a LED connected to Uno B’s D12 should be. I set Uno B’s D13 as OUTPUT
so that I can switch it up/down using button widget
at the app, I did this to make sure that my board is accessible from the internet. So the only Uno B’s pin that I want to remotely switch from Uno A is D12.
I can’t open Serial Monitor because the COM port is busy, used to connect the board to the internet.
Dmitriy:
Please post your code.
BRB.
imsyf
November 1, 2016, 2:37am
17
Dmitriy:
Please post your code.
Here is the code.
Sender - Uno A:
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3);
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>
#define MY_VP 5 // debugging purpose
#define PLEASE_REMOTE_THIS_VP 27
char auth[] = "4814623d761e4446b708bxxxxxxxxxxx";
WidgetBridge bridge1(V1);
SimpleTimer timer;
static bool value = true;
void setup(){
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(auth, Serial);
while(!Blynk.connect());
timer.setInterval(1000L, blynkAnotherDevice);
}
void loop(){
Blynk.run();
timer.run();
}
BLYNK_CONNECTED() {
bridge1.setAuthToken("fbfdc905b5694bff90c32xxxxxxxxxxx");
}
void blynkAnotherDevice(){
if(value){
Blynk.virtualWrite(MY_VP, 1); // debugging purpose
bridge1.virtualWrite(PLEASE_REMOTE_THIS_VP, 1);
}
else{
Blynk.virtualWrite(MY_VP, 0); // debugging purpose
bridge1.virtualWrite(PLEASE_REMOTE_THIS_VP, 0);
}
value = !value;
}
Receiver - Uno B:
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3);
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
#define PLEASE_REMOTE_THIS_VP 27
#define BUTTON_FROM_APP_VP 8 // debugging purpose
#define REMOTE_THIS_VP_STATE 0 // to show PLEASE_REMOTE_THIS_VP's state in app
char auth[] = "fbfdc905b5694bff90c32xxxxxxxxxxx";
void setup(){
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(auth, Serial);
while(!Blynk.connect());
}
void loop(){
Blynk.run();
}
BLYNK_WRITE(PLEASE_REMOTE_THIS_VP){
int pinData0 = param.asInt();
Blynk.virtualWrite(REMOTE_THIS_VP_STATE, pinData0); // show bridged VP's state in app
}
BLYNK_WRITE(BUTTON_FROM_APP_VP){ // debugging purpose
int pinData1 = param.asInt();
digitalWrite(13, pinData1);
}
I’m kind of sceptic about BLYNK_WRITE(PLEASE_REMOTE_THIS_VP)
being executed.
@vshymanskyy A little help, maybe?
imsyf
November 1, 2016, 4:06am
18
Does this problem happen simply because I’m using USB cable and not Ethernet/WiFi shield?
Dmitriy
November 1, 2016, 7:51am
19
@imsyf code seems fine to me. Are you sure your boards are online? How do you verify this?
imsyf
November 1, 2016, 8:48am
20
I use button widget from the app to toggle D13 in both of them, and it works.