Start a new topic

send temperature from Arduino to Nextion

 Hi Everyone

Hope you can help me. I'am new in Arduino and nextion, trying to build LED control and a temperature reading to the Nextion using DS18B20 sensor. I can read temperature on serial monitor but can figure out how to send the reading to my nextion, using this sketch


#include <DallasTemperature.h>
#include <OneWire.h>
#include "NexSlider.h"
#include "NexText.h"

#define ONE_WIRE_BUS 12
OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

int brightness = 0; // integer for interior led

NexSlider h0 = NexSlider(1, 2, "h0"); // LED control
NexText t0 = NexText(0, 2, "t0"); // text field for temperature

char buffer[10] = {0};

NexTouch *nex_Listen_List[] =
{

&h0,
&t0,
NULL
};

void h0PopCallback(void *ptr) // Slider to set interior light (0-255 PWM)
{
uint32_t number = 0;
char temp[10] = {0};

dbSerialPrintln("h0PopCallback");

h0.getValue(&number);
brightness = number;
analogWrite(7, brightness);
}



void setup(void)
{
{
nexInit();
h0.attachPop(h0PopCallback, &h0);
pinMode(7, OUTPUT); //setting port OUTPUT
}
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
sensors.begin();
}


void loop(void)
{
nexLoop(nex_Listen_List);
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures();
Serial.println("DONE");
Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0));
delay(1000);

}

1 Comment

 

Forum has been closed since the Nov. 15, 2017  23:59:59.

Please use new forum nextion.itead.cc