Reading data from Blynk

Hello all,

I am working on a simple project where a Joystick on the Blynk app on my phone sends it's values to the Arduino and then gets printed on my LCD screen. For the most part, things are working. The app and the Arduino are connected, and the LCD screen does print data. However, the data isn't accurate and doesn't represent the joystick's movements whatsoever. Below is the Arduino Code, Terminal code, and some screenshots from the app.

Arduino Code

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3);

#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 8, 9, 7);

char auth[] = "64ff1d6e5ff646a5aff28f52de11c914";

int x = 6;
int y = 5;

unsigned long xvalue;
unsigned long yvalue;

void setup() {

  SwSerial.begin(9600);
  Blynk.begin(auth);

  Serial.begin(9600);
  lcd.begin(16, 2);

  lcd.clear();

  pinMode(x, INPUT);
  pinMode(y, INPUT);
  
}

void loop() {

  Blynk.run();

  int xvalue = analogRead(x);
  int yvalue = analogRead(y);

  lcd.setCursor(0, 0);
  
  lcd.print("X:");
  lcd.print(xvalue);

  lcd.setCursor(0, 1);
  
  lcd.print("Y:");
  lcd.print(yvalue);
  
  delay(100);
}

Terminal code:

cd ./Documents/Arduino/libraries/Blynk/scripts
bash ./blynk-ser.sh

Below are some photos of the interface from my phone.

I have no idea about Blynk, but making people download and unzip files to see your photos will not get you as much help as properly posting the photos. See here posting photos

groundfungus:
I have no idea about Blynk, but making people download and unzip files to see your photos will not get you as much help as properly posting the photos. See here posting photos

Fixed, thank you for the tip.

  pinMode(x, INPUT);
  pinMode(y, INPUT);

Analog pins are input only. Diddling with the digital pins is probably not a good idea.

  int xvalue = analogRead(x);
  int yvalue = analogRead(y);

That is NOT getting data from the phone app.

PaulS:

  pinMode(x, INPUT);

pinMode(y, INPUT);



Analog pins are input only. Diddling with the digital pins is probably not a good idea.

I don't have an option on the app to connect the Joystick to analog pins.

PaulS:

  int xvalue = analogRead(x);

int yvalue = analogRead(y);



That is NOT getting data from the phone app.

Then what is? I've never done something like this before.

I don't have an option on the app to connect the Joystick to analog pins.

The joystick on the phone app is sending some data to the Arduino. You need to figure out what it is sending.

Then what is?

Presumably, something in the Blynk instance is connecting the joystick to digital pins 5 and 6. I have no idea how a library that you didn't post a link to is working.

PaulS:
The joystick on the phone app is sending some data to the Arduino. You need to figure out what it is sending.
Presumably, something in the Blynk instance is connecting the joystick to digital pins 5 and 6. I have no idea how a library that you didn't post a link to is working.

The library is available for download here.

Here is more information about the joystick.

Here is an example code for the Joystick, however that code is optimized for the Ethernet Shield, and I don't have that. I modified it to this but still no luck:

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3);
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 8, 9, 7);

char auth[] = "YourAuthToken"; // isnert auth token here

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

  lcd.begin(16, 2);
}

BLYNK_WRITE(V1) {
  
  int x = param[5].asInt();
  int y = param[6].asInt();

  lcd.setCursor(0, 0);
  
  lcd.print("X = ");
  lcd.print(x);

  lcd.setCursor(0, 1);
  
  lcd.print("; Y = ");
  lcd.print(y);
}

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

Why did you change the index into the param array? It looks to me like that index values should still be 0 and 1.

Look at your picture if you need proof - on the far left edge of the picture.

PaulS:
Why did you change the index into the param array? It looks to me like that index values should still be 0 and 1.

Look at your picture if you need proof - on the far left edge of the picture.

I see. Let me fix that.

Okay, let me recap here.

In the code in the OP the LCD prints

X:
Y:

followed by a bunch of nonsense numbers.

In this recent code, nothing is printed on the LCD screen.

I may found a lead though. In the Joystick settings I can only select PWM pins, and the data range is from 0-255. Does that spark any ideas on how to read it and then display it?

In the code in the OP the LCD prints

We've already agreed that that does does not make sense.

I'm not sure what should call BLYNK_WRITE(), or what the heck V1 means. But, it would appear that it is not being called.

You should be asking these questions on the Blynk forum.

PaulS:
We've already agreed that that does does not make sense.

I'm not sure what should call BLYNK_WRITE(), or what the heck V1 means. But, it would appear that it is not being called.

You should be asking these questions on the Blynk forum.

I did, not a response in 6 hours... Selective hearing I guess.

V1 stands for virtual 1 which is a 'pin' in the app. But that makes no sense because I'm connecting this to PWM pins on the arduino... sigh, I guess I'll just wait for an answer on the other forum.

Selective hearing I guess.

More likely, unrealistic expectations on your part.

Dear chummer1010, we have hundreds of emails and forum posts... And 99% of them are answered.

In your case, you need to: read about Virtual Pins: Documentation for Blynk, the most popular IoT platform for businesses. and this: Documentation for Blynk, the most popular IoT platform for businesses.

There are examples in the library explaining that.

So basically you need to get the data from the app and then print it to the screen

I discovered a solution, thanks to your post!

I needed to connect the joystick pin to a virtual in the app. Also, Paul, BLYNK_WRITE is called in void loop by Blynk.run();

Final code:

#include <SoftwareSerial.h>
SoftwareSerial SwSerial(2, 3);
#define BLYNK_PRINT SwSerial
#include <BlynkSimpleSerial.h>

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 8, 9, 7);

char auth[] = "64ff1d6e5ff646a5aff28f52de11c914";

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

  lcd.begin(16, 2);
}

BLYNK_WRITE(V2) {
  
  int x = param[0].asInt();
  int y = param[1].asInt();

  lcd.setCursor(0, 0);
  
  lcd.print("X:");
  lcd.print("   ");

  lcd.setCursor(2, 0);
  lcd.print(x);

  lcd.setCursor(0, 1);
  
  lcd.print("Y:");
  lcd.print("   ");
  
  lcd.setCursor(2, 1);
  lcd.print(y);
  
}

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

Thank you and sorry for my unnecessary impatience.