Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Nextion and Bascom

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1141
Location: SYDNEY

australia.gif
PostPosted: Thu Nov 28, 2019 7:43 am    Post subject: Nextion and Bascom Reply with quote

Using the Nextion display with Bascom.

The displays handle all the graphics:
It is all stored in the flash on the display you design it on your PC
upload photos and graphics to the editor to be used on your display
upload to the display is done via RS232 or simpler by micro SD card
It handles the touch events for you

Communication to the avr is serial RS232

There is a limited instruction set that can be used to get the display to do some work
but its not well documented.

The first thing to do is to give the items on the screen useful names
because when you change pages the default ones get re-used
as an example the first touch button on a page gets named bt1
so every page you make will have a bt1 making it difficult to work out which page sent it

It can do a pop up page over the present one
it comes with examples of keyboards one is a number pad which pops up enabling numbers to be input.
It has a user password function.

The enhanced versions have more ram , flash , a RTC , general purpose IOs which can do PWM and faster cpu.
I have the enhanced version.

The size of buttons on the screen will need to be determined on the screen
for users to be able to work with big enough for a finger or stylus

This covers some of their functions more will follow as I learn them.

next post I will show a animated screen with the nextion code that does it

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1141
Location: SYDNEY

australia.gif
PostPosted: Thu Nov 28, 2019 11:39 am    Post subject: Reply with quote

Now here is the animation

Slider tool

https://youtu.be/tSEj0gExWAI



h0 , h1 , h2 , h3 are the sliders
va0 , va1 , va2 , va3 are local variables to the page
Note variables can be made global available to all pages
the code runs in a timer which forms a loop
the first 4 lines are setting the slider to the variable value
each slider can have a value from zero to 100
as we go through the loop we add 10 to the variable
the if statement tests if it is greater than 100
if it is then it is set to 1

The code that runs the slider is
Code:

h0.val=va0.val
h1.val=va0.val
h2.val=va1.val
h3.val=va3.val
va0.val=va0.val+10
if(va0.val>100) //Pay attention to the format, there must be brace before and behind it, and  the brace must take up ONE line
{
  va0.val=1
}
va1.val=va1.val-10
if(va1.val<1) //Pay attention to the format, there must be brace before and behind it, and  the brace must take up ONE line
{
  va1.val=100
}
if(va3.val>100)
{
  va3.val=1
}
if(va3.val<1)
{
  va3.val=100
}
if(va2.val>1)
{
  va3.val=va3.val-10
}
if(va2.val<2)
{
  va3.val=va3.val+10
}
 


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1141
Location: SYDNEY

australia.gif
PostPosted: Thu Nov 28, 2019 11:53 am    Post subject: Reply with quote

Now full animation with picture box added

https://youtu.be/irECmmy1-ds

Picture box code animation
Pictures are loaded into the editor and are assigned a number automatically in the order loaded
they can however be moved up and down in the order manually
the animation is done by using a timer loop to load images in succession
the same way an animated GIF works
p2 is picture 2 box and pictures 62 to 66 are loaded one after the other
as we go through the timer loop
the if statement takes us back to image 62 (the first of the series)
when we come to the last in the series
this all shows as the yellow dots moving through the circle
with four picture boxes

Regards Paul

Code:

p2.pic=va4.val
va4.val=va4.val+1
if(va4.val>66) //Pay attention to the format, there must be brace before and behind it, and  the brace must take up ONE line
{// brace before
  va4.val=62
}// brace behind
p3.pic=va6.val
va6.val=va6.val+1
if(va6.val>71) //Pay attention to the format, there must be brace before and behind it, and  the brace must take up ONE line
{
  va6.val=67
}
p4.pic=va7.val
va7.val=va7.val+1
if(va7.val>76) //Pay attention to the format, there must be brace before and behind it, and  the brace must take up ONE line
{
  va7.val=72
}
 
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 896
Location: France

france.gif
PostPosted: Sun Dec 15, 2019 6:51 pm    Post subject: only bascom Reply with quote

hi Paul,
A new set of tools for nextion :https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14537
JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 896
Location: France

france.gif
PostPosted: Wed Feb 05, 2020 3:52 pm    Post subject: Reply with quote

hi Paul or other Nextion user,

I need your feedback on the 7" capacitive nextion screens.
do you use them?
I use the 5" resistive is good but by dint of tapping on the screen, it seems less reactive . before ordering (100) I would like your opinion.
Is is working as the resistifs ?

I notice a bug ? : I have to display 30 text fields, the last one was never write. I had too add a "waitms xx" between fields. now is is working well maybe my buffer was too small too.
JP

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1141
Location: SYDNEY

australia.gif
PostPosted: Thu Feb 06, 2020 12:17 am    Post subject: Reply with quote

Hello JP
I have the 7 inch enhanced.
Have had no problems so far but have not had time to really use it
spent time getting the object colours and background colour so they are easy to see
yet to get working with bascom but sending from terminal on PC to test.
The intelligent series would be nice for a commercial project
it can play video files which would be good for help instructions.

I measured the current yesterday it draws 350ma.

I was busy with making a battery cabinet for my NiFe before Xmas
then at my home here on NSW south coast smoke and ash was the problem
luckily fires were not a direct threat.

Regards Paul
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 896
Location: France

france.gif
PostPosted: Sun Feb 09, 2020 4:55 pm    Post subject: Reply with quote

hello Paul
Indeed we followed the terrible fires that ravaged Australia and I had a thought for my friend whom I have never seen.
Today in France we have a very strong winter storm. A weather to work at home. Hoping the mains is not cut off.
Thanks for your message, I ordered the display.
I'll pass on my experience with it.

JP Wink

_________________
pleasure to learn, to teach, to create
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1141
Location: SYDNEY

australia.gif
PostPosted: Mon Feb 10, 2020 1:00 am    Post subject: Reply with quote

Hello JP
The important thing I have found with the display is not to get too small
if your going to use it with finger and not a stylus.
Nextion Global variables & objects are needed when you want
a screen to stay the way it is when changing to another screen
so when you return its not back to default
so like bascom local variables and normal global variables.

The number object only accepts digits no decimal point.

The float object also only accepts digits and you have to set up the position of the decimal point
so if you have 12.34 you send it 1234 then set attributes ws0 and ws1
ws0 is number of digits to left of decimal point
ws1 is number of digits to right of decimal point

so we set them both to 2 and get 12.34 but if we send it 123 we get 01.23

This requires some code in bascom to work out what to send as we need to remove decimal points from numbers
I find it simpler to convert to string and use text box object on the nextion as the decimal point is inserted by bascom.

So what use are the number and float objects?
They will allow you to use the nextion code to manipulate numbers.

A note on the fires here :
We have had storms here too dumping 40 to over 200 mm of rain in places
this has put out one of the fires and suppressed others
put water into our dams
but has also caused local flooding and ash run off into the dams

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1141
Location: SYDNEY

australia.gif
PostPosted: Mon Feb 17, 2020 3:32 am    Post subject: Reply with quote

Now some bascom driving nextion
The avr sends QPIGS with CRC to my inverter it sends back its present status
This is what comes back
(243.4 50.0 230.3 50.0 0437 0432 010 404 50.50 000 083 0035 00 09 079.8 50.63 00000 00110110 00 00 00455 010

243.4 is grid volts ,50.0 grid frequency , 230.3 inverter output volts, 50.0 frequency
So it can be seen that a space is the delimiter
Also there is a CRC at the end with CRLF
The split command chops it up into its parts each work() variable contains a value
I send each value to the nextion text box to be displayed
I use the covx command on the nextion to convert text box to number
I use the if command on nextion to control animation
For example if the grid voltage is too low the grid display flashes red/green
va13.val is a number variable
this runs in a timer of 500ms
Note use of ==
Code:

covx gridvolts.txt,va13.val,0,0
if(va13.val<210&&p1.pic==52)
{
  p1.pic=53
}else
{
  p1.pic=52
}
 



bascom code
put together from other projects so messy

Code:



  $regfile = "m644pdef.dat"                                 ' specify the used micro


$crystal = 8000000                                          ' used crystal frequency
'$baud = 9600                                                ' use baud rate
$hwstack = 50
$swstack = 50
$framesize = 50


 Dim Alen As Byte
Dim Onlongs(17) As Long                                     'numbers to sort Long, Word, Byte as needed
'Dim X As Byte

'Dim Sol(Cool As Byte

Dim Crc_16 As String * 2
Dim Work2 As Word At Crc_16 Overlay
Dim Work(35) As String * 40
Dim Thecrc As Word
Dim Rs232 As Byte
Dim Uart_command_in As String * 50
Dim Uart_command As String * 254
Dim Aruart_command(253) As Byte At Uart_command Overlay
Dim Send_command As String * 50
Dim Send_bytes(49) As Byte At Send_command Overlay
Dim Crcstr As String * 2
Dim Crcwrd As Word At Crcstr Overlay
Dim Z As Byte
Dim Task As Byte
Dim Temp1 As String * 20
Dim Temp2 As Byte
Dim V As Byte
Dim Crc As Byte


Declare Sub Chopup
Declare Sub Find_command
Declare Sub Cal_crc16
Declare Sub Nextion

Config Com1 = 9600 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Config Com2 = 2400 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0

Enable Interrupts

Config Serialin = Buffered , Size = 254



Open "com2:" For Binary As #1
Open "com1:" For Binary As #2
V = 0

Work(1) = "Booting"
Print #2 , "status.gridvolts.txt=" + Chr(34) + Work(1) + Chr(34);
                  Call Nextion
                  Wait 2
'Print #2 , "status.gridvolts.txt=" + Chr(34) + Work(1) + Chr(34);
                  'Call Nextion



Do
     Task = 0
 ' Do
  ' If Ischarwaiting() = 1 Then
    '  Rs232 = Inkey()                                       'get a character from the buffer

     ' If Rs232 = 13 Or Len(uart_command_in) > 49 Then       'uart_command full or enter key sent


      '         Print
       '        Uart_command_in = Ucase(uart_command_in)     'make uper case


       '    Exit Do

      'Else
      '   Uart_command_in = Uart_command_in + Chr(rs232)     'add the character to the uart_command buffer
        ' Print Chr(rs232) ;
     ' End If
   'End If

  'Loop

  ' Select Case Uart_command_in
            Select Case V
               Case 0                                       'get the state of inverter
                   Uart_command_in = "QPIGS"
                   Task = 1
                      V = 1
               Case 1
                   Uart_command_in = "QMOD"  'get what mode inverter is in
                   Task = 3
                      V = 0


            End Select

  ' End Select

      Send_command = Uart_command_in
      Uart_command_in = ""

    Z = Len(send_command)

  Thecrc = Crc16(send_bytes() , Z)                          'workout the CRC
  Swap Thecrc
  'Print Hex(thecrc)
  Crcwrd = Thecrc
    Wait 2
    Print #1 , Send_command ; Crcstr ; Chr(13) ;

  Do
   If Ischarwaiting(#1) = 1 Then
      Rs232 = Inkey(#1)                                     'get a character from the buffer

      If Rs232 = 13 Or Len(uart_command) > 253 Then         'uart_command full or enter key sent
             Delchars Uart_command ,(13)
             Call Find_command
                ' Delchars Uart_command , "("
           ' Print "RETURNED DATA>" ; Uart_command
           'Print
             Print Uart_command
             Uart_command = ""
         Exit Do
      Else
         Uart_command = Uart_command + Chr(rs232)           'add the character to the uart_command buffer

      End If
   End If

  Loop

  Wait 2






Loop

 End                                                        'end program





 Sub Find_command
     Local A As String * 3
     Local B As Byte
     Local C As Byte
      Local D As Byte
      Local E As Long
     C = &B00000111




   Call Cal_crc16
   If Crc = 1 Then
       Select Case Task
                    'Print "Status bits>" ; Work(17)
               Case 1

                  Call Chopup
                     'get the state of inverter
                   Delchar Work(1) , 1                      'remove the (
                   'work(17)      staus bits

                   'Print ">>Inverter Stats<<"
                  ' Print "Grid Volts=" ; Work(1)

                  Print #2 , "status.gridvolts.txt=" + Chr(34) + Work(1) + Chr(34);
                  Call Nextion

                   'Print "Grid Frequency=" ; Work(2)
                  Print #2 , "status.gridfreq.txt=" + Chr(34) + Work(2) + Chr(34);
                  Call Nextion
                   'Print "AC Output Volts=" ; Work(3)
                  Print #2 , "status.outvolts.txt=" + Chr(34) + Work(3) + Chr(34);
                  Call Nextion
                   'Print "AC Output Frequency" ; Work(4)
                  Print #2 , "status.outfreq.txt=" + Chr(34) + Work(4) + Chr(34);
                  Call Nextion
                   'Print "Apparent Power=" ; Work(5)
                  Print #2 , "status.outwatts.txt=" + Chr(34) + Work(5) + Chr(34);
                  Call Nextion
                   'Print "Active Power=" ; Work(6)
                   'Print "Load=" ; Work(7) ; "%"
                  Print #2 , "status.load.txt=" + Chr(34) + Work(7) + Chr(34);
                  Call Nextion
                   'Print "Buss Volts=" ; Work(Cool
                  Print #2 , "status.bussvolts.txt=" + Chr(34) + Work(8) + Chr(34);
                  Call Nextion
                   'Print "Battery Volts=" ; Work(9)
                  Print #2 , "status.battvolts.txt=" + Chr(34) + Work(9) + Chr(34);
                  Call Nextion
                   'Print "Battery Discharge Current=" ; Work(16) ; "Amps"
                   'Print "Battery Current=" ; Work(10) ; "Amps"
                   'are we discharging
                    Temp2 = Val(work(16))
                  If Temp2 > 0 Then                         'discharging
                   Print #2 , "status.va10.val=2";
                   Call Nextion
                   Print #2 , "status.battsgn.txt=" + Chr(34) + "-" + Chr(34);
                   Call Nextion
                      Work(16) = Str(temp2)
                   Print #2 , "status.battamps.txt=" + Chr(34) + Work(16) + Chr(34);
                   Call Nextion
                   Else                                     'charging
                   Print #2 , "status.va10.val=1";
                   Call Nextion
                   Print #2 , "status.battsgn.txt=" + Chr(34) + "+" + Chr(34);
                   Call Nextion
                   Temp2 = Val(work(10))
                   Work(10) = Str(temp2)
                   Print #2 , "status.battamps.txt=" + Chr(34) + Work(10) + Chr(34);
                   Call Nextion

                  End If
                  Call Nextion



                   'Print "Battery Capacity=" ; Work(11) ; "%"
                   Print #2 , "status.soc.txt=" + Chr(34) + Work(11) + Chr(34);
                  Call Nextion
                   'Print "Inverter Heat Sink Temp=" ; Work(12) ; "C"
                   Print #2 , "status.inverttmp.txt=" + Chr(34) + Work(12) + Chr(34);
                  Call Nextion
                   'Print "PV Current into Battery=" ; Work(13) ; "Amps"
                   'Print "PV Voltage=" ; Work(14) ; "Volts"
                  Print #2 , "status.panlvolts.txt=" + Chr(34) + Work(14) + Chr(34);
                  Call Nextion
                   'Print "Solar Charger Battery Voltage=" ; Work(15) ; "Volts"

                   Print #2 , "status.panlamps.txt=" + Chr(34) + Work(13) + Chr(34);
                  Call Nextion
                   A = Mid(work(17) , 1)
                      If A = "1" Then
                          'Print "SBU Priority=Yes"
                               Else
                          'Print "SBU Priority=No"
                      End If
                   A = Mid(work(17) , 2)
                      If A = "1" Then
                         'Print "Configuration Change"
                          Else
                         'Print "Configuration No Change"
                      End If
                    A = Mid(work(17) , 3)
                      If A = "1" Then
                         'Print "Solar Charger Firmware Updated"
                          Else
                         'Print "Solar Charger Firmware Not Updated"
                      End If
                     A = Mid(work(17) , 4)
                      If A = "1" Then
                        'Print "Load is On"
                          Else
                        'Print "Load is Off"
                      End If

                      A = Mid(work(17) , 6 , 3)
                           D = Binval(a)
                      'Select Case D

                           ' Case 0

                            'Print "No charging On"

                            'Case 6

                            'Print "Solar charging On"

                            'Case 5

                            'Print "AC charging On"

                            'Case 7

                            'Print "Solar & AC Charging On"

                      'End Select




                'QMOD device mode
               Case 3
             'Print
            ' Print "QMOD>>>";
            ' Print Uart_command

             Work(1) = Mid(uart_command , 2 , 1 )

               Select Case Work(1)

                   Case "P"                                 'POWER ON MODE
                      Work(4) = "POWER ON MODE"

                   Case "S"                                 'STANDBY MODE
                      Work(4) = "STANDBY MODE"

                   Case "L"                                 'LINE MODE

                     Work(4) = "LINE MODE"

                   Case "B"                                 'BATTERY MODE
                     Work(4) = "BATTERY MODE"

                   Case "F"                                 'FAULT MODE
                     Work(4) = "FAULT MODE"

                   Case "H"                                 'POWER SAVING MODE
                     Work(4) = "POWER SAVING MODE"


               End Select
                   'Work(4) = "status.invmode.txt=" + Work(4)
                   Print #2 , "status.invmode.txt=" + Chr(34) + Work(4) + Chr(34);
                  Call Nextion


             Uart_command = ""




       End Select

     Else

       Work(1) = "BAD CRC"
       Print #2 , "status.gridvolts.txt=" + Chr(34) + Work(1) + Chr(34);
                  Call Nextion
                  Wait 2
   End If

 End Sub


 'get the individual parameters returned
 Sub Chopup

 Local Lx As Byte

           Lx = Split(uart_command , Work(1) , " ")
           'Print "we had " ; Lx ; " lots of data returned"

 End Sub

 Sub Cal_crc16
 Local Z As Word
 Local Rcrc As Word
 Local Rcrc2 As Word



   Z = Len(uart_command)
   Z = Z - 2                                                'last two bytes are crc
   'Print "Z is>" ; Z
  Rcrc = Crc16(aruart_command() , Z)                        'calculate  the CRC
   Swap Rcrc                                                'bytes are in reverse order to what is sent to us
  'Print "Cal CRC  is>" ; Hex(rcrc)
  Crc_16 = Right(uart_command , 2)                          'get the last two bytes the crc
  Rcrc2 = Work2                                             'this is a word variable overlayed on Crc_16

 ' Print "The sent crc>" ; Hex(rcrc2)
   If Rcrc = Rcrc2 Then                                     'they match data good
        ' Print "CRC OK
        Crc = 1
       Else
        ' Print "CRC BAD"
        Crc = 2

   End If

 End Sub


 Sub Nextion

 Printbin #2 , &HFF ; &HFF ; &HFF
 Waitms 200
 End Sub
 


The attached HMI file is for the 7inch enhanced
regards Paul
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum