Value display bit map not transferred to history graph

Is there a way to get the history graph to use the same bit mapping as the value display? I have scaled the bits to read as voltage in my value display but the history graph only reads bits. Is this something that will be implemented in the future? Can i get the value to display the correct decimal placing for volts instead of mV?

I have tried to do the mapping on the Photon but i’m so confused. Mapping virtual pins sounds so easy but i cannot find any examples using the photon that make any sense. All the examples use arduino libraries except for the one Pavel made for temp and humidity with a core but even that uses a sensor library that i’m not implementing.

Also, the way i’m using Blynk does my data only log when the app is open? sorry for all the noobie questions

// This #include statement was automatically added by the Particle IDE.
include "blynk/blynk.h"
char auth[] = "29a7a366a9954f63a1f54da11018945f";

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

void loop()
{
map(A0, 0, 4095, 0, 18.65);
map(A1, 0, 4095, 0, 18.65);
map(A2, 0, 4095, 0, 18.65);
Blynk.run();
}

Isnt there an easy way to scale the reading for both the history graph and the value displays? Is there a way to do this without timers? I tried to comment out what I’m not using from this example but it doesn’t compile.

#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"
//#include "Adafruit_DHT/Adafruit_DHT.h"
//#define DHTPIN 2     // what pin we're connected to
//#define DHTTYPE DHT22		// DHT 22 (AM2302)
//#define BLYNK_PRINT Serial

SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void);   //Prototype for timer callback method

//DHT dht(DHTPIN, DHTTYPE);
//float main, aux, acc, 
//int main, mainRaw, aux, auxRaw, acc, accRaw,

char auth[] = "";  

void setup() {
    Serial.begin(9600);
    updateTimer.SetCallback(OnTimer);
    Serial.println("DHTxx test!");
    dht.begin();
    delay(5000); // Allow board to settle
    pinMode(A0, input);
    pinMode(A1, input);
    pinMode(A2, input);
    Blynk.begin(auth);
}

void loop() {

    Blynk.run();
    updateTimer.Update();
    
    //h = dht.getHumidity();
    //t = dht.getTempCelcius();
    mainRaw = analogRead(A0);
    auxRaw = analogRead(A1);
    accRaw = analogRead(A2);
    main = map(mainRaw, 0, 4096, 0, 18.65);
    aux = map(auxRaw, 0, 4096, 0, 18.65);
    acc = map(accRaw, 0, 4096, 0, 18.65);
  
// Check if any reads failed and exit early (to try again).
	if (isnan(h) || isnan(t) || isnan(f)) {
		Serial.println("Failed to read from DHT sensor!");
		return;
	}
}

void OnTimer(void) {  //Handler for the timer, will be called automatically
  
  main = ((int) (main * 10) / 10.0);
  aux = ((int) (aux * 10) / 10.0);

  Blynk.virtualWrite(21, main);
  Blynk.virtualWrite(22, aux);
  Blynk.virtualWrite(23, acc);
}

Also comment dht.begin() from the setup. That should make it compile.

and this bit too:

if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(“Failed to read from DHT sensor!”);
return;

Thank you for the reply, I did as you suggested and still receive the following

"
In file included from blynk/BlynkParticle.h:16:0,
from blynk/BlynkSimpleParticle.h:14,
from blynk/blynk.h:2,
from cruisecontroldev4.cpp:1:
blynk/BlynkApiParticle.h:78:6: warning: #warning “analogInputToDigitalPin not defined => Named analog pins will not work” [-Wcpp]
#warning “analogInputToDigitalPin not defined => Named analog pins will not work”
^
cruisecontroldev4.cpp: In function ‘void setup()’:
cruisecontroldev4.cpp:24:17: error: ‘input’ was not declared in this scope
Serial.begin(9600);
^

cruisecontroldev4.cpp: In function ‘void loop()’:
cruisecontroldev4.cpp:37:5: error: ‘mainRaw’ was not declared in this scope
Blynk.run();
^

cruisecontroldev4.cpp:38:5: error: ‘auxRaw’ was not declared in this scope
updateTimer.Update();
^

cruisecontroldev4.cpp:39:5: error: ‘accRaw’ was not declared in this scope

 ^

cruisecontroldev4.cpp:40:5: error: ‘main’ was not declared in this scope
//h = dht.getHumidity();
^

cruisecontroldev4.cpp:41:5: error: ‘aux’ was not declared in this scope
//t = dht.getTempCelcius();
^

cruisecontroldev4.cpp:42:5: error: ‘acc’ was not declared in this scope
mainRaw = analogRead(A0);
^

cruisecontroldev4.cpp: At global scope:
cruisecontroldev4.cpp:49:1: error: expected declaration before ‘}’ token
// Check if any reads failed and exit early (to try again).
^

make[1]: *** […/build/target/user/platform-6cruisecontroldev4.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.
"

Turn this:

//int main, mainRaw, aux, auxRaw, acc, accRaw,

into:

int main, mainRaw, aux, auxRaw, acc, accRaw;

Because you use those variables in the void OnTimer() you need to either declare them their as int or use them as global vars.

edit-

Apparently you are using a ParticleCore of which I don’t know much, but these are the two flaws I see, at least, when it would be an Arduino. Also be careful of the last " " " quote. I think that is wrong too.

Its getting closer but still won’t compile, heres the current program I’m trying to run, followed by the errors. Thank you for the help!
include “blynk/blynk.h”
include “blynk/BlynkSimpleParticle.h”
include “SparkCorePolledTimer/SparkCorePolledTimer.h”
//#include “Adafruit_DHT/Adafruit_DHT.h”
//#define DHTPIN 2 // what pin we’re connected to
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define BLYNK_PRINT Serial

SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it’s timeout in milliseconds
void OnTimer(void); //Prototype for timer callback method

//DHT dht(DHTPIN, DHTTYPE);
//float main, aux, acc;
int main, mainRaw, aux, auxRaw, acc, accRaw;

char auth[] = "token";

void setup() {
Serial.begin(9600);
updateTimer.SetCallback(OnTimer);
Serial.println("DHTxx test!");
//dht.begin();
delay(5000); // Allow board to settle
pinMode(A0, Input);
pinMode(A1, Input);
pinMode(A2, Input);
Blynk.begin(auth);
}

void loop() {

Blynk.run();
updateTimer.Update();

//h = dht.getHumidity();
//t = dht.getTempCelcius();
mainRaw = analogRead(A0);
auxRaw = analogRead(A1);
accRaw = analogRead(A2);
main = map(mainRaw, 0, 4096, 0, 18.65);
aux = map(auxRaw, 0, 4096, 0, 18.65);
acc = map(accRaw, 0, 4096, 0, 18.65);
// Check if any reads failed and exit early (to try again).
//if (isnan(h) || isnan(t) || isnan(f)) {
//Serial.println("Failed to read from DHT sensor!");
//return;
}
{

void OnTimer(void) { //Handler for the timer, will be called automatically

main = ((int) (main * 10) / 10.0);
aux = ((int) (aux * 10) / 10.0);
acc = ((int) (acc * 10) / 10.0)

Blynk.virtualWrite(21, main);
Blynk.virtualWrite(22, aux);
Blynk.virtualWrite(23, acc);
}

cruisecontroldev4.cpp:1:1: error: ‘include’ does not name a type

^

cruisecontroldev4.cpp: In function ‘void setup()’:
cruisecontroldev4.cpp:20:1: error: ‘updateTimer’ was not declared in this scope

^

cruisecontroldev4.cpp:24:13: error: ‘Input’ was not declared in this scope
Serial.begin(9600);
^

cruisecontroldev4.cpp:27:1: error: ‘Blynk’ was not declared in this scope
//dht.begin();
^

cruisecontroldev4.cpp: In function ‘void loop()’:
cruisecontroldev4.cpp:32:1: error: ‘Blynk’ was not declared in this scope
Blynk.begin(auth);
^

cruisecontroldev4.cpp:33:1: error: ‘updateTimer’ was not declared in this scope
}
^

cruisecontroldev4.cpp: At global scope:
cruisecontroldev4.cpp:48:1: error: expected unqualified-id before ‘{’ token
// Check if any reads failed and exit early (to try again).
^

make[1]: *** […/build/target/user/platform-6cruisecontroldev4.o] Error 1
make: *** [user] Error 2
Error: Could not compile. Please review your code.

These:

pinMode(A0, Input);
pinMode(A1, Input);
pinMode(A2, Input);

Gotta be (I think):

pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);

It may seem trivial, but capital letters make huge differences.

I think this in void loop():

updateTimer.Update()

has to be:

OnTimer.Update();

There is also one “{” after the closing “}” of the void loop(). Remove that.

THANK YOU @Lichtsignaal Its working! updateTimer was correct and i needed # before include in the libraries as well but thanks to you its online. Step one complete, cheers1

Heres my working code for my own reference, I seem to delete things by accident sometimes. Now I’m trying to get the value widget to return decimel voltage values, i think it has to do with INT instead of FLOAT

    #include "blynk/blynk.h"
    #include "blynk/BlynkSimpleParticle.h"
    #include "SparkCorePolledTimer/SparkCorePolledTimer.h"
    //#include "Adafruit_DHT/Adafruit_DHT.h"
    //#define DHTPIN 2 // what pin we're connected to
    //#define DHTTYPE DHT22	// DHT 22 (AM2302)
    //#define BLYNK_PRINT Serial

    SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
    void OnTimer(void); //Prototype for timer callback method

    //DHT dht(DHTPIN, DHTTYPE);
    //float main, aux, acc;
    float main, mainRaw, aux, auxRaw, acc, accRaw;

    char auth[] = "";

    void setup(){
    Serial.begin(9600);
    updateTimer.SetCallback(OnTimer);
    Serial.println("DHTxx test!");
    //dht.begin();
    delay(5000); // Allow board to settle
    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
    pinMode(A2, INPUT);
    Blynk.begin(auth);
    }

    void loop(){

    Blynk.run();
    updateTimer.Update();

    //h = dht.getHumidity();
    //t = dht.getTempCelcius();
    mainRaw = analogRead(A0);
    auxRaw = analogRead(A1);
    accRaw = analogRead(A2);
    main = map(mainRaw, 0, 4096, 0, 18.65);
    aux = map(auxRaw, 0, 4096, 0, 18.65);
    acc = map(accRaw, 0, 4096, 0, 18.65);
    //Check if any reads failed and exit early (to try again).
    //if (isnan(h) || isnan(t) || isnan(f)) {
    //Serial.println("Failed to read from DHT sensor!");
    //return;
    }

    void OnTimer(void) { //Handler for the timer, will be called automatically

    main = ((int) (main * 10) / 10.0);
    aux = ((int) (aux * 10) / 10.0);
    acc = ((int) (acc * 10) / 10.0);

    Blynk.virtualWrite(0, main);
    Blynk.virtualWrite(1, aux);
    Blynk.virtualWrite(2, acc);
    }

Here, I’ve cleaned it up a bit for you and moved the analogRead to the timed function. It’s not usefull in the main loop since it will be only used in the void where you read the pins.

#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"

SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void); //Prototype for timer callback method

float main, mainRaw, aux, auxRaw, acc, accRaw;

char auth[] = "blablauhcode here";

void setup(){
Serial.begin(9600);
updateTimer.SetCallback(OnTimer);

delay(5000); // Allow board to settle

pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);

Blynk.begin(auth);
}

void loop(){

Blynk.run();
updateTimer.Update();`
}

void OnTimer(void) { //Handler for the timer, will be called automatically

// read analog ports
mainRaw = analogRead(A0);
auxRaw = analogRead(A1);
accRaw = analogRead(A2);

main = map(mainRaw, 0, 4096, 0, 18.65);
aux = map(auxRaw, 0, 4096, 0, 18.65);
acc = map(accRaw, 0, 4096, 0, 18.65);

// This part makes it while numbers, if you remove the (int) before these ones you get two decimals :smile: 
main = ((int) (main * 10) / 10.0);
aux = ((int) (aux * 10) / 10.0);
acc = ((int) (acc * 10) / 10.0);

Blynk.virtualWrite(0, main);
Blynk.virtualWrite(1, aux);
Blynk.virtualWrite(2, acc);
}

See the notice in the code for your decimal issue :smile:

1 Like

Got it, thank you so much. Im sure ill get the hang of it soon enough:wink:

#include "blynk/blynk.h"
#include "blynk/BlynkSimpleParticle.h"
#include "SparkCorePolledTimer/SparkCorePolledTimer.h"

SparkCorePolledTimer updateTimer(5000); //Create a timer object and set it's timeout in milliseconds
void OnTimer(void); //Prototype for timer callback method

float main, mainRaw, aux, auxRaw, acc, accRaw;

char auth[] = "token";

void setup(){
Serial.begin(9600);
updateTimer.SetCallback(OnTimer);

delay(5000); // Allow board to settle

pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);

Blynk.begin(auth);
}

void loop(){

Blynk.run();
updateTimer.Update();
}

void OnTimer(void) { //Handler for the timer, will be called automatically

// read analog ports
mainRaw = analogRead(A0);
auxRaw = analogRead(A1);
accRaw = analogRead(A2);

main = map(mainRaw, 0, 4096, 0, 1865);
aux = map(auxRaw, 0, 4096, 0, 1865);
acc = map(accRaw, 0, 4096, 0, 1865);

main = (main / 100);
aux = (aux / 100);
acc = (acc / 100);

Blynk.virtualWrite(3, main);
Blynk.virtualWrite(4, aux);
Blynk.virtualWrite(2, acc);
}

Glad you solved it.
Why is this topic in Projects Made with Blynk category ?

It is a project to lock and unlock doors, start stop the engine, and raise lower the windows on my vehicle using blink or programmed logic. I’m also my monitoring two battery voltages and charging cycles from the alternator or the 100 watt panel on the roof. Obviously the post was about coding, I’ll be more selective with placement next time. Thanks for the great support!

Please move to the corresponding topic.
If it’s an issue - move it to Issues and Errors.

Thanks

@Pavel I dont see the control to move this topic, I would move it to “I need help with my project” if that is possible. Thank you