Start a new topic

i2c protocol

Can the Nextion display be used with the i2c ports?  


No, the Nextion is TTL RX/TX Serial based.

However, if you were using 2 - 16 channel muxes over I2C, then it would use I2C ports,

but I don't believe this is what you were referring to.

Well, no I wasn't.  And I definitely don't know enough about i2c to make (2) 16 channel mux.  That sounds complicated, and will probably end up putting my project over the maximum memory constraints, which it is already red-lining at now.



The 16 channel mux is a component ~1.50


http://www.ebay.com/itm/16CH-Analog-Digital-MUX-Breakout-Board-CD74HC4067-Precise-module-Arduino-/311374536627?hash=item487f5e5fb3:g:lkcAAOSwtnpXiEjA


Are you redlining for memory in your Nextion HMI design or in your MCU code?


The Arduino board is nearing the maximum limit.  


"Sketch uses 16,674 bytes (51%) of program storage space. Maximum is 32,256 bytes.

Global variables use 1,455 bytes (71%) of dynamic memory, leaving 593 bytes for local variables. Maximum is 2,048 bytes. "

I haven't fully implemented the rest of the functions I need.  I tried making my code more efficient and freed up 93 whole bytes "for local variables".  


The purpose of me asking about the i2c function, is because I am using a HC-05 bluetooth to communicate with an Android phone, and using the Nextion as the onboard control panel.  This project is for a keyless remote start system for a car - so I would use both the Nextion or the phone/Bluetooth to start & unlock the car.  I am having severe trouble getting both software-serial communications to work reliably at the same time.

In the communications, it is important that the Nextion has completed transmissions before you task it to receiving.  To me, the behaviour is such that the one (rx/tx) has a higher interrupt priority, but the Nextion device serial communications is not bidirectional USART - as such it was classified as TTL.  Most or many attempts for concurrent sending and receiving will create issues - so attempt to make certain you have received everything the Nextion is sending before sending.


The other thing to look into is "how chatty" is your HMI design?  If you can attempt to ensure that the Nextion is only sending data on actual important events (many Send Component IDs are great for debugging but are not really needed once you know your MCU will respond, try to limit the unnecessary to reduce the traffic and thus less chance of collision)


If you have the chance try a different combinations, perhaps one hardware serial (for the Bluetooth) and one software serial (Nextion) may provide better stability.  I could offer to look at your HMI design to see if there is anything I could recommend.  (Also which baud rates are you using?)  Maybe a second set of eyes may be of some help.

Patrick;


  Thanks for the offer.  I believe there are no events in my HMI project which are not sending or receiving that shouldn't.  As a matter of fact, there are less, since I am only trying to do a basic test with a few buttons instead of the whole design.  There are only 2 pages, and testing with only 1 page.


  I tried using the hardware serial port, except it causes too much work for me testing communications between the Bluetooth, Nextion, and me having to switch wires around every time I make a program change and re-upload.  After the project is installed and I test on the vehicle, it would make it even more difficult if I could not easily upload a program change without having to dismount and re-wire it INSIDE of the vehicle.



One more thought regarding baud rates.  If the max amount of data needed to be transferred is low, you can attempt to use a lower baud rate.  Lower baud rates give more sampling time and are perhaps more stable.  If at 9600 baud, the rough calculations are baud/10*0.94 or ~900 bytes of data per second.  So if total data between both devices needed is less than that 900 bytes, using 9600 baud provides more pronounced bits. Likewise, if total bytes needed is less than 225 bytes - 2400 baud.


I am not sure how many total bytes Nextion needs for simple button press, and release event.  Or a set-button text function.  I hope they would be less then 900 bytes.


The bluetooth application is sending or receiving less then 10 bytes at a time.  


I believe I was testing at 9600 the 2 software serial, and was using 9600 for the usb debug port.  Tried different baud rates and got less reliability with higher rates on the Bluetooth.  The baud rate seems to effect the speed to initially connect the bluetooth device (though I have not scientifically gauged it).  I was trying to set bluetooth baud high, not because I'm sending tremendous amount of data for pushbutton events, but because I want it to connect as fast as possible.


Even at 300 baud, a button press event should probably process faster to transmit a few bytes from the nextion for a button press without a noticeable delay.




Button press and release return codes are each 7 bytes.(probably not in rapid succession either).


Okay, I am going to go out on a limb:

Basic example for Serial Debug via USB and two soft serials

  - modify the pin numbers to which actual pins are being used

  - give this a shot just to see if you manage a stable connection

  - if it works, build up from there.

  - for now skip Nextion.h and deal with raw access.  How is the basic 2 soft-serial on memory


#include <SoftwareSerial.h>
SoftwareSerial portOne(10, 11);  // use this for Bluetooth, mod pin #s 
SoftwareSerial portTwo(8, 9);      // use this for Nextion, mod pin #s
void setup() {
  Serial.begin(115200);  // its USB, so 115 should be no problem
  while (!Serial) {
    ;
  }
  portOne.begin(38400);  // Bluetooth HC-05 default
  portTwo.begin(115200);  // Nextion can handle 115
}

 void loop() {
    portOne.listen();
    Serial.println("Data from port one:");
    while (portOne.available() > 0) {
        char inByte = portOne.read();
        Serial.write(inByte);
    }
    Serial.println();
    portTwo.listen();
    Serial.println("Data from port two:");
    while (portTwo.available() > 0) {
        char inByte = portTwo.read();
        Serial.write(inByte);
    }
   Serial.println();
}
    

 


After reading a bit more, perhaps limit the serials to 19200 on all three USB, BT and Nextion.

Do I have to do something extra to make the Nextion connect at 19200 or 115200? I think mine wants to connect at 9600.

If you upload your HMI over serial:

in the debug simulator,

select Send Command to: Simulator and Nextion Device  (Auto search and Connect)

Then send in the Instruction Input area

bauds=19200  // sets baud rate to 19200 and saves as default


If you upload your HMI with a microSD card:
In your first page PreInitialization Event put the bauds command
bauds=19200  // sets baud rate to 19200 and saves as default

compile and upload your HMI and run on your Nextion device.
This only needs to be done when you want to change the default baudrate.
Also, the command baud=19200 will change the baud rate but will not save.


Login or Signup to post a comment