Start a new topic

Software Serial, Nextion, Analog Interrupts problem

I posted this on Arduino forum.. However, everyone has alternative ideas to SoftSeria which don't work with a nextion object. Hopefully this forum can assist


By the way Nextion.h is not the Itead version as I find it too big for porting onto a UNO.


This is a stripped down version of project code that I have been using for quite a long time which is exhibiting the same problem as the main code. I recompiled and downloaded for a small alteration and now getting errors in the reading from the software serial RX. I have compiled into a UNO ( its normal usage on pins 8/9) and a Mega 2560 (10/11) as a trial with the same bad results... If I deactivate the ADC_Init() then it all comes right as you can see on the docx. file   Tried everything I can over last week! 
What is annoying is this code has been working fine for months! 
Basically I am sampling 5 analogs, one for a spot check and the others scanned over 1/4 second to get the maximum and minimum voltage. Communication on serial 8/9 on UNO is to a Nextion.


Included is aNextion File for testing, essentially buttons initiating Print commands Two options provided



Any help gratefully received.

docx
(16.8 KB)
HMI
HMI
ino
(3.5 KB)
ino

Nextion TTL Serial

http://support.iteadstudio.com/support/discussions/topics/11000012112

It doesn't super matter how you push bytes as long as you push bytes.


What becomes issues beyond a page0.t0.txt="Hello World"ÿÿÿ

   has MCU dependences, Compiler dependencies, and Language dependencies.


UNO has one Serial port.

 - you might find it better to swap debugging on a SoftwareSerial and

   give the Hardware Serial port to Nextion.


So if I get this right, your ADC is sampled 2500 times x 4 channels and 5 times on spot check.

 - 10005 samples @ 0.104ms set on a timer interrupt.

So each iteration of loop takes 1040.52ms + whatever if something was in the Serial buffer.


And this is unbridled, occurring every loop iteration.

   you've purposely left no time for SoftwareSerial to sample the line

   - which has to be sampled multiple times per bit - because its bit-banged.

  each bit will take 0.01736ms or a full byte needs 0.1736ms to come in


Further, I am not certain if the interrupt itself is a conflict - .... see the MCU documentation.

but I would be most certain that there is little chance of software serial being able to

come in when you have ADC chewing up 1040.5ms of the loop iteration.


A loop iteration if you have Hardware Serial handling your serial should be in

 terms of 100K to 200K times per second, you will need even less in your loop

 when you want to allow for software serial to bit-bang it out on two pins.


Your Mega has three very good HardwareSerial ports ...

No

The ISR counts the number of samples per channel and when it reaches 2500 provides Vmax and Vmin to the main program. The ISR is stopped, a new channel selected, and then ISR is restarted.


The main program continues as always, as is the case with a free running interrupt and hence should catch a serial .  As I said it all worked well before......


I could change the debug to software serial... Will see how it goes...


The only reason I ported onto the Mega was to see if the fault was hardware dependent. It wasn't

More thinking then ...

When the character is not received as it was sent

 - your interrupt has indeed prevented SoftwareSerial in doing its task.

the delay(10) of 10ms as a halt in place

  is already 57.6 chars worth at 57600 bps.

But you'll find a hardware serial more reliable.


Yes. The problem is on the UNO R3 the USB interface uses the hardware serial so its hard to get to operate on Nextion

What I don't understand is why the first character is correct ie 'B' in almost all cases but the next is wrong. Its almost as if nextion.listen() is not taking in the serial buffer


If you have a Arduino Mega 2560, use that one. Use a hardware serial port for the Nextion display. Pin 10 and 11 are not a hardware serial port.

I try to avoid the SoftwareSerial as much as possible, but I have to admit that I do use a Nextion display with an Arduino Uno. Instead of SoftwareSerial, I tried AltSoftSerial. It works, but an Arduino Uno is not the best board for a Nextion display anyway.

 

Hi

Just for anyone's interest the problem was the baud rate. over 19200 then the ADC crashed.. I have not found out why this should be. Originally there was limitations in softwareserial of this nature but I understood these had been fixed with the version in the latest arduino IDE

Please listen to us. You need a better board than the Arduino Uno. Since you already have a Arduino Mega 2560 board, use that one, because it has free hardware serial ports. You also might have to reconsider why you take the ADC samples in that way.

The SoftwareSerial makes it possible to add an extra serial port. It is great that a library like that exists. It also makes it almost impossible to do something else. That is terrible. Stay away from it if you don't know the consequences.
Login or Signup to post a comment