Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN Data

This forum is for the discussion of other projects on Megasquirt/Microsquirt hardware that don't fit into any of the other forums

Moderators: jsmcortina, muythaibxr

gui67
Experienced MS/Extra'er
Posts: 164
Joined: Tue Mar 23, 2010 12:10 pm
Location: Strasbourg, France

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by gui67 »

OK,
I managed to get the nextion display a value sent by the arduino, this is now OK.
Next step is getting a value from CANbus
gui67
Experienced MS/Extra'er
Posts: 164
Joined: Tue Mar 23, 2010 12:10 pm
Location: Strasbourg, France

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by gui67 »

For the displaying on the nextion, there were 2 problems:
- I did not have the same ground between Nextion and the Arduino
-the serial baudrate was 115200 on the code, mine works at 9600.

Now for the can reception, it seems that this condition is never reached: if ( CANbus.read(rxmsg) ).
I asked to light the led but it does not go on.
I i put the same command after the if, adding else: then it goes on.
Maybe you have an idea why the can does not respond?

At the moment the MS3 is on the bench with a Jimstim.

I am using the MSGPIO as trans controller and communication between both is OK in the car.

When I plug an oscilloscope on the CAN wires, there is a signal comming from MS3.
gui67
Experienced MS/Extra'er
Posts: 164
Joined: Tue Mar 23, 2010 12:10 pm
Location: Strasbourg, France

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by gui67 »

OK,
It seems to be working now.
The CAN tx and Rx were inverted...
Raymond_B
Super MS/Extra'er
Posts: 1394
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas
Contact:

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by Raymond_B »

Sorry for the slow reply. Your PMs got tangled up in my work SPAM filter.

Anyway, swapping the CAN TX RX is easy to do, been there done that. Also if you look my Teensy file there is a provision to turn on writing data out to the serial monitor of the IDE. Reading your steps you seem to be going too fast :) Get each step working first then tie it together at the end. You're going to want to set your Nextion to 115,200 as 9600 will prove too slow as you progress. I thought I posted how, but if you google changing the baud rate there is a lot of info on how to do it.

Glad to see you are making progress!
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3X/v3.57
http://www.buildpics.org/
gui67
Experienced MS/Extra'er
Posts: 164
Joined: Tue Mar 23, 2010 12:10 pm
Location: Strasbourg, France

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by gui67 »

Hi Bertrand,
Thanks for the work you have done and posted.
Here is a quick video of what I managed to do for the moment:
https://youtu.be/jvXAq8F5xCs
I plan to add a 3rd screen with the MS status
Like you said it is very slow for the moment, I really need to increase baud rate to 115200.

Is there a way to get data that is not broadcast from MS3 but that are in the Msgpio Tcu? Like transmission line pressure, lock-up, manual mode... What James' CAN gauge was able to do:
http://www.msextra.com/forums/viewtopic ... 8&start=60
tbaggins
Helpful MS/Extra'er
Posts: 49
Joined: Fri Apr 15, 2016 7:41 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by tbaggins »

To set the baud rate faster, send the command "bauds=115200" once, you should be able to do this in the Nextion editor, and it will save.

Here are all of the commands if you are not familiar (i'm sure you are if you have it working already). http://wiki.iteadstudio.com/Nextion_Ins ... ables_List

There is an arduino library that is MUCH easier to use than the library provided by the HMI.
The link to it is here:
https://github.com/bborncr/nextion

Attached is my boost control project (rename to .ino) to show how the commands work with this library. One note is that I had to change the default serial port in the setup file of the library for my arduino pro mini, as there is only 1 serial port on the unit. The library above is written for an Arduino Mega and software serial on it.
-in the library folder, open nextion.h and comment out the line "define USE_SOFTWARE_SERIAL //Comment this line for use HardwareSerial"

"HardwareSerial & nextion = Serial;" <<<this renames your hardware serial port to "nextion", there was a reason I had to do this but I can't remember what it was. I think it had to do with there only being one serial port on the mini, which won't be an issue with a Teensy.
THEN
"Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps" <<<this uses the new serial port name, so that you can change text in your display by using "myNextion.setComponentText("component name", "text you want")".

Like I said, if anyone has questions, just PM me, and if you want me to look at your code send it. I have a Teensy 3.2, 2 displays, and the megasquirt. I haven't used them together yet, but this thread is making me think about it. I am pretty good with the Arduino environment. The boost control project has worked flawlessly since installing it, and these displays are pretty cool (and fast) once you get them sorted out. I have had not problems at 9600 being to slow, in fact I had to set delays in the code because it was refreshing too fast. Working with CAN bus messages likely adds timing, but sending a serial message is at 9600 is fast. It is likely something else in your code that is holding things up, like waiting for a reply from the megasquirt CAN broadcast. If you don't break your code into functions and only run the code that you need for the page that the nextion is on, it will bog down your processing on the Teensy.
Last edited by tbaggins on Sat May 07, 2016 5:56 am, edited 2 times in total.
2003 Mustang 2V stock harness splice, MS3X v3.0 parallel install, full sequential, HPX MAF, Ford Ev6 47lb injectors, COP, custom 8 BIP373 box, E85 pump, teflon lined return style fuel system, 39 lb base fuel pressure, Twin Turbo @ 7lbs boost, Dual 4 port boost solenoids, Dual 14point7 widebands
matthunter1448
Helpful MS/Extra'er
Posts: 140
Joined: Fri Jun 06, 2008 11:15 pm
Location: Spanaway, Wa

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by matthunter1448 »

tbaggins wrote:To set the baud rate faster, send the command "bauds=115200" once, you should be able to do this in the Nextion editor, and it will save.

Here are all of the commands if you are not familiar (i'm sure you are if you have it working already). http://wiki.iteadstudio.com/Nextion_Ins ... ables_List

There is an arduino library that is MUCH easier to use than the library provided by the HMI.
The link to it is here:
https://github.com/bborncr/nextion

Attached is my boost control project to show how the commands work with this library. One note is that I had to change the default serial port in the setup file of the library for my arduino pro mini, as there is only 1 serial port on the unit. The library above is written for an Arduino Mega and software serial on it.
-in the library folder, open nextion.h and comment out the line "define USE_SOFTWARE_SERIAL //Comment this line for use HardwareSerial"

"HardwareSerial & nextion = Serial;" <<<this renames your hardware serial port to "nextion", there was a reason I had to do this but I can't remember what it was. I think it had to do with there only being one serial port on the mini, which won't be an issue with a Teensy.
THEN
"Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps" <<<this uses the new serial port name, so that you can change text in your display by using "myNextion.setComponentText("component name", "text you want")".

Like I said, if anyone has questions, just PM me, and if you want me to look at your code send it. I have a Teensy 3.2, 2 displays, and the megasquirt. I haven't used them together yet, but this thread is making me think about it. I am pretty good with the Arduino environment. The boost control project has worked flawlessly since installing it, and these displays are pretty cool (and fast) once you get them sorted out. I have had not problems at 9600 being to slow, in fact I had to set delays in the code because it was refreshing too fast. Working with CAN bus messages likely adds timing, but sending a serial message is at 9600 is fast. It is likely something else in your code that is holding things up, like waiting for a reply from the megasquirt CAN broadcast. If you don't break your code into functions and only run the code that you need for the page that the nextion is on, it will bog down your processing on the Teensy.
How do u break it up per page ?

Sent from my SM-N920T using Tapatalk
tbaggins
Helpful MS/Extra'er
Posts: 49
Joined: Fri Apr 15, 2016 7:41 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by tbaggins »

I would put everything into functions. For page 1 for example, you make it into a funtion and then in your Void loop() you call that function use if then statements. Have some sort of variable that fills to tell the code what page you are on, and then use that to decide where to go with the If Then statements (or case statements, not sure which uses less processing power, IF THEN is easier for me)

Example:

Code: Select all

int screenNumber = 1;

void setup() {
//setup stuff
}

Void loop() {
String message = myNextion.listen(); //check for message

  // if a message is received check where it came from and what it says, always do this to check the buffer for a page change before running code
  if(message != ""){
    if (message == "65 00 09 00 ff ff ff") {
         screenNumber = 1;
    elseif (message == "64 00 09 00 ff ff ff") {
         screenNumber = 2;
    }
  } //etc etc for all of the pages and the messages that the nextion will send when you switch pages

If (screenNumber == 1) {
  function1();
  }
elseif (screenNumber == 2) {
  funtion2();
  } //etc etc etc, a function for each page you run.

} //end of void loop

void function1() {
//send CANBUS message asking for ONLY the values that are on this page1
//break the message apart into string variables, i.e RPM or whatever
//then fill these variables on your screen by sending a myNextion.setComponentText("t1", "RPM") command for each thing on the screen
} //etc etc, do this for each function tied to a page.

Sorry this is a quick reply, my wife is yelling at me to come to bed. I will elaborate more, but GENERALLY it is much more efficient to run only the code you need, instead of having a huge block of code that has to be executed and then does nothing for you before you get to what actually will fill in your text on the screen

The nextion broadcasts a serial message when it changes screen. You use this to fill the variable that tells the code what screen you are on. The code checks for a message, changes the screen number if needed, and then executes the function associated with the screen.
Last edited by tbaggins on Sat May 07, 2016 5:59 am, edited 1 time in total.
2003 Mustang 2V stock harness splice, MS3X v3.0 parallel install, full sequential, HPX MAF, Ford Ev6 47lb injectors, COP, custom 8 BIP373 box, E85 pump, teflon lined return style fuel system, 39 lb base fuel pressure, Twin Turbo @ 7lbs boost, Dual 4 port boost solenoids, Dual 14point7 widebands
tbaggins
Helpful MS/Extra'er
Posts: 49
Joined: Fri Apr 15, 2016 7:41 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by tbaggins »

I think I am going to play with this over the weekend. I will see what I can come up with, it seems fun. I haven't dealt with CANBUS yet, my car is a ford and uses the ford PWM for messages. Like I said, if anyone wants advice on their code, send me a PM. I can give you an email you can send it to me to.
2003 Mustang 2V stock harness splice, MS3X v3.0 parallel install, full sequential, HPX MAF, Ford Ev6 47lb injectors, COP, custom 8 BIP373 box, E85 pump, teflon lined return style fuel system, 39 lb base fuel pressure, Twin Turbo @ 7lbs boost, Dual 4 port boost solenoids, Dual 14point7 widebands
tbaggins
Helpful MS/Extra'er
Posts: 49
Joined: Fri Apr 15, 2016 7:41 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by tbaggins »

Just to clarify, why are people using the Teensy rather than an Arduino? Multiple serial ports and size/processor power? (this is not meant to sound condescending, great work has been done in this thread)
I was under the assumption that the Teensy was able to connect to the CAN BUS network directly without additional hardware. I started looking into it today, and it seems like you need another module (TI SN65HVD230D, MCP2551, etc.) for the "CAN BUS" on the Teensy to work? Am I missing something?
2003 Mustang 2V stock harness splice, MS3X v3.0 parallel install, full sequential, HPX MAF, Ford Ev6 47lb injectors, COP, custom 8 BIP373 box, E85 pump, teflon lined return style fuel system, 39 lb base fuel pressure, Twin Turbo @ 7lbs boost, Dual 4 port boost solenoids, Dual 14point7 widebands
matthunter1448
Helpful MS/Extra'er
Posts: 140
Joined: Fri Jun 06, 2008 11:15 pm
Location: Spanaway, Wa

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by matthunter1448 »

Confirmed today 2 screens with teensy 3.2 working great

Sent from my SM-N920T using Tapatalk
grom_e30
Super MS/Extra'er
Posts: 4451
Joined: Thu Mar 08, 2012 12:44 pm
Location: UK

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by grom_e30 »

tbaggins wrote:I started looking into it today, and it seems like you need another module (TI SN65HVD230D, MCP2551, etc.) for the "CAN BUS" on the Teensy to work? Am I missing something?
the teensy has a can controller built in a bit like the mcp2515 found on the arduino can shields but it still needs a can Transceiver. the arduino due and the chipkit max32 both still need the Transceiver as well.
1990 bmw 320i daily driver with m20b25 ms3 sequential fuel, 380cc injectors, d585 coil near plug, home made cam sync, launch control, fan control, vss, homebrew egt logging what's next????
Raymond_B
Super MS/Extra'er
Posts: 1394
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas
Contact:

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by Raymond_B »

tbaggins wrote:Just to clarify, why are people using the Teensy rather than an Arduino? Multiple serial ports and size/processor power? (this is not meant to sound condescending, great work has been done in this thread)
I was under the assumption that the Teensy was able to connect to the CAN BUS network directly without additional hardware. I started looking into it today, and it seems like you need another module (TI SN65HVD230D, MCP2551, etc.) for the "CAN BUS" on the Teensy to work? Am I missing something?
I liked the Teensy's power, versatility, and support.

You need a CAN transceiver with whatever micro you use.
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3X/v3.57
http://www.buildpics.org/
tbaggins
Helpful MS/Extra'er
Posts: 49
Joined: Fri Apr 15, 2016 7:41 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by tbaggins »

That makes sense, I bought a Teensy a few months ago because of the processor speed and the number of outputs, it is a nice little board. It has been sitting around waiting for a good project (like this possibly). I didn't realize that it had CAN on board until I received it, and I assumed that it wouldn't need additional hardware. There are a few products out that do CAN-in-the-middle attacks in vehicles, essentially filtering messages from stereos, steering wheel buttons, or displays on dashboards and responding in lieu of the ECU (or controlling the car in a malicious attack). I am working on something like this for one of my cars OBDII output. The protocol is much more difficult to use, and hardware is almost non-existent for emulating Ford PWM signals.

So I want to clarify, the CAN BUS messages from the megasquirt are constantly broadcast without having to send a query, correct? In OBDII the sender device asks for the data it wants to see, and the ECU responds. Reading the CAN Broadcasting document (http://www.msextra.com/doc/pdf/Megasqui ... adcast.pdf) it looks like it just broadcast everything selected in the settings 20 times a second?
2003 Mustang 2V stock harness splice, MS3X v3.0 parallel install, full sequential, HPX MAF, Ford Ev6 47lb injectors, COP, custom 8 BIP373 box, E85 pump, teflon lined return style fuel system, 39 lb base fuel pressure, Twin Turbo @ 7lbs boost, Dual 4 port boost solenoids, Dual 14point7 widebands
matthunter1448
Helpful MS/Extra'er
Posts: 140
Joined: Fri Jun 06, 2008 11:15 pm
Location: Spanaway, Wa

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by matthunter1448 »

Yes it's constantly broadcast as far as I know i didn't have to send megasquirt any thing just turn it on in the can dash broadcast setting

Sent from my SM-N920T using Tapatalk
Raymond_B
Super MS/Extra'er
Posts: 1394
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas
Contact:

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by Raymond_B »

Yes exactly, you simply choose your method of broadcasting. One is a pared down version for things like dash displays and the other is full on broadcasting. On the full broadcasting you can also edit the starting ID and exactly what you want, the list is really large.
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3X/v3.57
http://www.buildpics.org/
MostHated
MS/Extra Newbie
Posts: 34
Joined: Fri May 02, 2014 7:12 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by MostHated »

Hello,
Great work on this project. One question I have is, how does the display look in direct sunlight? My pal is building an Exocet, so everything will always be in direct lgiht, and he wants a digital dash, but has no idea how screens that are compatible with things like this will look in direct light. If you get a chance, can you go out in to the light with it and see how readable it is?

Thanks!
MostHated
Raymond_B
Super MS/Extra'er
Posts: 1394
Joined: Thu Mar 06, 2014 2:17 pm
Location: Texas
Contact:

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by Raymond_B »

I'll look, I think it's pretty washed out. You might be able to try some high contrast or reverse contrast stuff.

When I get it powered back up I'll check it out in sunlight.
1995 Ford Lightning. Dart based 427 Windsor, Novi 2000, full sequential, E-85, etc. MS3X/v3.57
http://www.buildpics.org/
RNAsEqUeNcE
MS/Extra Newbie
Posts: 13
Joined: Sat Sep 25, 2010 8:45 pm

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by RNAsEqUeNcE »

Hello!

Thank you to everyone in this thread for your efforts on development. I have purchased all the listed hardware as I need a gauge solution for my motorcycle. I will inform of my progress in due time.
Joeli0
Helpful MS/Extra'er
Posts: 58
Joined: Tue Dec 29, 2015 6:38 am

Re: Nextion 3.2" LCD Display + Teensy 3.2 + Megasquirt CAN D

Post by Joeli0 »

I am starting this project next week. Can anyone screen shot their settings in TS for how the CAN is broadcast or is it as simple as enabling it. This is my first go round but has me excited with the possibilities. Thanks.
Post Reply