Nextion 3.2" and Teensy 3.2 no communication

Status
Not open for further replies.

CCC

New member
Hi.

I have tried looking for some answers and no solution found for my problem. I am running a Nextion 3.2" LCD with a Teensy 3.2, however I do not get any communication. I have tried using different Serial Ports however still no luck. Everything worked on my Arduino Nano and coppied the code exactly from the Nano to the Teensy using Teensyduino. I want to run specific voltages from a DAC and then measure with a ADC and display on the LCD. Can someone please help?

Code:
#include "Nextion.h" // Nextion Library
#include <Wire.h> // ADC Library
#include <Adafruit_ADS1015.h> // ADC Library
#include <PWM.h> // PWM Library
#include <SPI.h> // Serial Communication Library

#define PGA 1
#define VREF 2.048
#define VFSR VREF/PGA
#define FSR (((long int)1<<23)-1)

//#define DAC8574_ADD 0x98
#define DAC8574_ADD 0x4C // allowing for RW bit being added
#define DAC8574_CTR 0x34 // broadcast to all dac channels

// Choose the correct ADC
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */

float adc0;
float adc1;
float adc2;
float adc3;
float differentialresult;
// After Multiplication
float adc0_new;
float adc1_new;
float adc2_new;
float adc3_new;
float differentialresult_new;
char buffer0[10] = {0}; // Buffer to display result
char buffer1[10] = {0}; // Buffer to display result
char buffer2[10] = {0}; // Buffer to display result
char buffer3[10] = {0}; // Buffer to display result

// DAC
volatile byte MSB;
volatile byte data;
volatile byte LSB;
//volatile char SPI_RX_Buff[3];
volatile byte *SPI_RX_Buff_Ptr;
byte val = 0;
unsigned int pwmvalue;
float pwmvoltage;

NexText Result0 = NexText(0,1,"Result0");
NexText Result1 = NexText(0,2,"Result1");
NexText Result2 = NexText(0,3,"Result2");
NexText Result3 = NexText(0,4,"Result3");

NexTouch *nex_listen_list[] =
{
&Result0,
&Result1,
&Result2,
&Result3,

NULL
};

void SetDACvoltage(unsigned int channel, float voltage) // Sub routine to pick the channel and the value to be sent
{
int DACCmd = 0; // Temp holder for DAC command
switch (channel)
{
case 0: DACCmd= 0x10; break; // Adress 0 selects Channel A - The first 1 is to set the value automatically on the output
case 1: DACCmd= 0x12; break; // Adress 2 selects Channel B - The first 1 is to set the value automatically on the output
case 2: DACCmd= 0x14; break; // Adress 4 selects Channel C - The first 1 is to set the value automatically on the output
case 3: DACCmd= 0x16; break; // Adress 6 selects Channel D - The first 1 is to set the value automatically on the output
default: break;
}

voltage = (voltage - 0.0042)/0.9998; // Calibration
pwmvoltage = ((voltage)/5)*65535; // Input voltage without offset value (0.01)
pwmvalue = (int) pwmvoltage;

Wire.beginTransmission(DAC8574_ADD); // transmit to device (address 0x98)
Wire.write(DACCmd); // This is the channel that is to be set (e.g. address 0x10)
Wire.write(pwmvalue >> 8); // Shift the 16 bit therefore send the first byte first (MSB)
Wire.write(pwmvalue); // Send LSB (The second byte) and ignores the upper half
Wire.endTransmission(); // Stop transmitting
}

void setup() {
// Initialize
nexInit(); // Initialize Nextion Display

Serial.begin(9600); // Start serial comunication at baud = 9600

ads.begin();

Wire.begin(DAC8574_ADD);

}

void loop() {

SetDACvoltage(0,0.362); // Set given voltage
SetDACvoltage(1,0.583); // Set given voltage
SetDACvoltage(2,1.275); // Set given voltage
SetDACvoltage(3,1.854); // Set given voltage

adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
adc0_new = (adc0*0.1875)/1000;
adc1_new = (adc1*0.1875)/1000;
adc2_new = (adc2*0.1875)/1000;
adc3_new = (adc3*0.1875)/1000;

dtostrf(adc0_new, 7, 5, buffer0);
dtostrf(adc1_new, 7, 5, buffer1);
dtostrf(adc2_new, 7, 5, buffer2);
dtostrf(adc3_new, 7, 5, buffer3);
Result0.setText(buffer0); // From ButtonTest_1
Result1.setText(buffer1);
Result2.setText(buffer2);
Result3.setText(buffer3);

nexLoop(nex_listen_list); // Check for any touch event
}

After uploading, The Arduino IDE gives me these errors:

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexPage.cpp: In member function 'bool NexPage::show()':

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexPage.cpp:25:13: warning: unused variable 'buffer' [-Wunused-variable]

uint8_t buffer[4] = {0};

^

C:\Program Files (x86)\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexRtc.cpp: In member function 'bool NexRtc::write_rtc_time(char*)':
 
Just a guess, maybe that Nextion lib is trying to talk on Serial, which only goes to the Arduino Serial Monitor with Teensy. On Arduino Nano, Serial goes to both the USB and pins 0 & 1. If you’ve connects the Nextion to those pins on Teensy, you need to use Serial1.
 
Hi PaulStoffregen. Thank you for your quick response. Your comment made me think about my setup and you were correct. When I did the setup for the Arduino Nano, I changed the NexConfig.h file to work for Serial0 and the Teensy pin 0 and pin 1 is used with Serial1. So all I did is I went back to the NexConfig.h File and changed it to Serial1 and everything is working perfectly!
 
Status
Not open for further replies.
Back
Top