I am using an Arduino 101 with a Max31850 K thermocouple. This code reads and writes to my serial port and all works well accurate temperatures. It also connect to the BLYNK app but I cannot get the real temp number on the value display S widget. It writes the word “HIGH” not what I see on the serial.
I am connected to pin 2 on the Arduino 101 and using D2 on the widget. Can anyone help?
Here is the code:
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “YourAuthToken”;
BLEPeripheral blePeripheral; #define ONE_WIRE_BUS 2
/-(Connect to Pin 2 )-/
/-----( Declare objects )-----/
/* Set up a oneWire instance to communicate with any OneWire device*/ OneWire ourWire(ONE_WIRE_BUS);
/* Tell Dallas Temperature Library to use oneWire Library / DallasTemperature sensors(&ourWire); void setup() {
Serial.begin(9600);
delay(1000);
/-( Start up the DallasTemperature library )-*/
blePeripheral.begin();
sensors.begin();
Serial.println(“Waiting for connections…”); }
void loop() {
Serial.println();
Serial.print(“Requesting temperature…”); sensors.requestTemperatures(); // Send the command to get temperatures Serial.println(“DONE”);
Same concept, different devices. Still, this is what I use to transmit temp and humidity readings from my Mega over to Blynk.
void climateCheck()
{
h = dht.readHumidity();
f = dht.readTemperature(true);
Blynk.virtualWrite(V0, f); // Set Virtual Pin 0 frequency to PUSH in Blynk app (Value Display)
Blynk.virtualWrite(V1, h); // Set Virtual Pin 1 frequency to PUSH in Blynk app (Value Display)
//Serial.print(f);
//Serial.print(h);
}
As Jamin said, get rid of delay all together and use timers. They are simple to use. Just put put related code into a function, and set that function to be ran at whatever frequency you want. I set mine to 3000 so I get a reading every 3 seconds. This is how timer.run() in the loop works. It’s just another loop, or series of loops if you have multiple functions.
yes, it looks much cleaner, isn’t it? but you should have to do this on your first post, at the top of this page use the edit button.
regarding your question, i think the problem is (among what @Jamin and the others say) , that you are reading the state of the digital pin in the widget (you are reading d2). this is why it reads “high”. (the “value” of a digital pin is either 1 or 0. actually the temperature value is obtained from reading a digital signal, a lots of 0 and 1)
to display the actual temperature value, you should pass the sensor reading to a virtual pin, and use that in the widget. look into virtual pins in the documentation.
Thank you all for your input. I am new to this so I am having trouble using virtual pins and the example because I get various before token errors depending on where I interject the virtual code.
When you say pass on the sensor to virtual pin, can you show me exactly where it goes in the code?
first, about simple timer:
simple timer is used for invoking periodically some functions. this is used instead of the delay(); if you’re using delay to time your events, you’re not halting just the function you wish to time, but the whole code on the mcu. this is not a good practice, especially for boards with internet / bluetooth etc connections.
you have to initialize first, outside of any functions: SimpleTimer timer;
then, you have to create a function what you will call periodically through simple timer:
void myTimerEvent()
{
// You can send any value at any time.
// Please don’t send more that 10 values per second.
Blynk.virtualWrite(V5, millis() / 1000);
}
observe, that here we are sending a value (the uptime in seconds) to a virtual pin: V5
next, you have to setup how often you wish to run this function. this is made inside the void setup() function:
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
you have to put timer.run(); into the void loop()
and last, just create a display widget in the app, set virtual pin V5, and set the frequency to push
it should work now. if you wish to display the temperature in display widget instead of uptime, you simply replace in code:
SUCCESS…Thank you very much from all who supported me. I got rid of the delay and incorporated the virtual 5 pin with push. I now get an accurate temperature.
I needed a proof before building the real project. It will read 6 type K thermocouples that are attached to the cylinder heads on my airplane engine. I want to monitor those on my iPad as I fly.
I already have the plane wired ready to go.
I may be back at some point. Again, I appreciate your expertise and patience.
glad you made it working!
just take it easy with the airplane + blynk combo, all this blynk stuff is surely not designed to use where one’s life depends on it!
and do not forget, that the wifi or ble is not 100% stable and blynk actually needs internet on the app side to work even with ble!
Thanks for the concern but this would be for information only. However, I wanted to learn how to use all the tools as I am righting an apple app to replace the BLYNK on my iPad. It does not need WiFi
You are asking that here… heretic (just kidding).
What you are describing is more a direct hardware to physical display option. But I suppose Bluetooth and/or USB On-The-Go connectivity might be other options (not sure about OTG ever being supported with Blynk?)
Did not think of that. I think the BLYNK app is awesome, in the end I need to do something else or Ask BLYNK the question. Thank you for the information.
some time ago i’ve used this to create a very simple app, using arduino uno + bluetooth hc-5 module, and switch a led on/off on arduino with my phone, and displaying some values on phone.