Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Nextion and Bascom
Goto page 1, 2, 3, 4  Next
 
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: 1257
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: 1257
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: 1257
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: 1161
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: 1161
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: 1257
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: 1161
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: 1257
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: 1257
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:






  'Interface between MPP solar products and PC terminal



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



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




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 Word

Dim V As Byte
Dim Crc As Byte


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



$lib "glcdKS108.lbx"

'Config Graphlcd = 240x64 , Dataport = Portc , Controlport = Porta , Ce = 5 , Cd = 6 , Wr = 3 , Rd = 4 , Reset = 7 , Fs = 0 , Mode = 6

Config Graphlcd = 128 * 64sed , Dataport = Porta , Controlport = Portc , Ce = 2 , Ce2 = 3 , Cd = 7 , Rd = 6 , Reset = 4 , Enable = 5



 Setfont Font8x8



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

Config Serialin0 = Buffered , Size = 20 , Bytematch = 13
Config Serialin1 = Buffered , Size = 150
Enable Interrupts


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

Temp1 = "Booting"

'Print #2 , "get page"
  'Call Nextion
   ' Wait 1
  'Call Get_chr

Print #1 , "status.gridvolts.txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                  'Wait 2
'Print #2 , "status.gridvolts.txt=" + Chr(34) + Work(1) + Chr(34);
                  'Call Nextion
                Cls
                Setfont Font8x8
               Lcdat 1 , 1 , "BOOTING"


Do
     'Task = 0















  ' 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 mode inverter is in
                   Task = 3
                      V = 2


               Case 2
                   Uart_command_in = "QPGS0"                'get inverter one state
                   Task = 4
                      V = 3


               Case 3
                   Uart_command_in = "QPGS1"                'get inverter two state
                   Task = 4
                      V = 0


            End Select
                     'Temp1 = "dog"
             'Print "data" ; Temp1
            'Wait 4
  ' End Select

        'Uart_command_in = "QPIGS"

      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 #2 , Send_command ; Crcstr ; Chr(13) ;
    'Print #2 , Send_command ; Crcstr ; Chr(13) ;
    'Print #1 , "QPIGS" + Chr(183) + Chr(169) + Chr(13);


  Wait 2

  While Ischarwaiting(#2) = 1
      Rs232 = Inkey(#2)                                     'get a character from the buffer

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



             Temp2 = Instr(uart_command , "NAKss" )

             If Temp2 > 0 Then                              'inverter did not accept command
               Uart_command = ""
               Clear Serialin1
               Print #1 , "gridvolts.txt=" ; Chr(34) ; "NAKss" ; Chr(34);
                  Call Nextion
               'Print #2 , ""
               'Print #2 , "not accepted"
               'Print #2 , ""
                  Else
                        Call Find_command
             End If





             Uart_command = ""
             Clear Serialin1


      Else
         Uart_command = Uart_command + Chr(rs232)           'add the character to the uart_command buffer

      End If
  Wend
         Screenchng:
  While Ischarwaiting(#1) = 1
      Rs232 = Inkey(#1)                                     'get a character from the buffer

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



                         'make uper case
           Z = Len(uart_command_in)
                 ' Z = Z - 2
                Temp1 = Left(uart_command_in , Z )
                                 Temp1 = Ucase(temp1)
                                         Cls
                                        Lcdat 6 , 1 , Temp1
     Select Case Temp1

            Case "STATUS"
                Cls
               Lcdat 1 , 1 , "STATUS"
                              Lcdat 7 , 1 , Temp1

             Case "STATUS2"

                Cls
               Lcdat 1 , 1 , "STATUS2"
                             Lcdat 7 , 1 , Temp1

            Case "SETTINS"

                Cls
               Lcdat 1 , 1 , "SETTINGS"
                              Lcdat 7 , 1 , Temp1
         End Select


              Uart_command_in = ""
           Clear Serialin0

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



Loop

 End                                                        'end program





 Sub Find_command
     Local A As String * 3
     Local B As String * 1
     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 #1 , "gridvolts.txt=" ; Chr(34) ; Work(1) ; Chr(34);
                  Call Nextion

                   'Print "Grid Frequency=" ; Work(2)
                  Print #1 , "gridfreq.txt=" ; Chr(34) ; Work(2) ; Chr(34);
                  Call Nextion
                   'Print "AC Output Volts=" ; Work(3)
                  Print #1 , "outvolts.txt=" ; Chr(34) ; Work(3) ; Chr(34);
                  Call Nextion
                   'Print "AC Output Frequency" ; Work(4)
                  Print #1 , "outfreq.txt=" ; Chr(34) ; Work(4) ; Chr(34);
                  Call Nextion
                   'Print "Apparent Power=" ; Work(5)
                   Temp2 = Val(work(5))
                   Temp1 = Str(temp2)
                  Print #1 , "outwatts.txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Active Power=" ; Work(6)
                   'Print "Load=" ; Work(7) ; "%"
                   Temp2 = Val(work(7))
                   Temp1 = Str(temp2)
                   Temp1 = Temp1 + "%"
                  Print #1 , "load.txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Buss Volts=" ; Work(Cool
                  Print #1 , "bussvolt.txt=" ; Chr(34) ; Work(8) ; Chr(34);
                  Call Nextion
                   'Print "Battery Volts=" ; Work(9)
                  Print #1 , "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(10))


                  Print
                  Print "work10" ; Work(10)
                  Print
                   Temp2 = Val(work(10))
                  Select Case Temp2
                      Case Is > 0
                         'Temp2 = Val(work(10))
                         Work(10) = Str(temp2)
                         'Work(10) = "+" + Work(10)

                          Print #1 , "battamps.txt=" ; Chr(34) ; Work(10) ; Chr(34);
                          Call Nextion
                      Case 0
                       Temp2 = Val(work(16))
                       If Temp2 = 0 Then
                          Temp2 = 1
                       End If

                       Work(16) = Str(temp2)
                       Work(16) = "-" + Work(16)
                       Print #1 , "battamps.txt=" ; Chr(34) ; Work(16) ; Chr(34);
                       Call Nextion



                  End Select


                   'Print "Battery Capacity=" ; Work(11) ; "%"
                   Temp2 = Val(work(11))
                   Temp1 = Str(temp2)
                   Temp1 = Temp1 + "%"
                   Print #1 , "soc.txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Inverter Heat Sink Temp=" ; Work(12) ; "C"
                   Temp2 = Val(work(12))
                   Temp1 = Str(temp2)
                   Print #1 , "inverttmp.txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "PV Current into Battery=" ; Work(13) ; "Amps"
                   'Print "PV Voltage=" ; Work(14) ; "Volts"
                   Temp2 = Val(work(14))
                   Temp1 = Str(temp2)
                  Print #1 , "panlvolts.txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Solar Charger Battery Voltage=" ; Work(15) ; "Volts"
                   Temp2 = Val(work(13))
                   Temp1 = Str(temp2)
                   Print #1 , "panlamps.txt=" ; Chr(34) ; Temp1 ; 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


             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"

                     Print #1 , "va12.val=1" ;
                     Call Nextion
                   Case "B"                                 'BATTERY MODE
                     Work(4) = "BATTERY MODE"
                     Print #1 , "va12.val=0" ;
                     Call Nextion
                   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 #1 , "invmode.txt=" ; Chr(34) ; Work(4) ; Chr(34);
                  Call Nextion


             Uart_command = ""

               'inverter two state
              Case 4

              '  V=0 QPGS1   V=1  QPGS0
              If V = 0 Then
                 B = "2"
                Else
                 B = ""
              End If

                  Call Chopup
                     'the state of parallel inverter
                     'work() variable contents
                     '1  = parallel number 1 to 9 zero = not exist
                     '2 inverter serial number
                     '3 working mode
                     '4 fault code
                   Delchar Work(1) , 1                      'remove the (
                   'work(17)      staus bits

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

            If Work(1) = "1" Then                           'yes have parra
                   'Print #2 , "yes have parra"
                   Print #1 , "serial" ; B ; ".txt=" ; Chr(34) ; Work(2) ; Chr(34);
                    Call Nextion
                  Print #1 , "gridvolts.txt=" ; Chr(34) ; Work(5) ; Chr(34);
                  Call Nextion

                   'Print "Grid Frequency=" ; Work(2)
                  Print #1 , "gridfreq.txt=" ; Chr(34) ; Work(6) ; Chr(34);
                  Call Nextion
                   'Print "AC Output Volts=" ; Work(3)
                  Print #1 , "outvolts.txt=" ; Chr(34) ; Work(7) ; Chr(34);
                  Call Nextion
                   'Print "AC Output Frequency" ; Work(4)
                  Print #1 , "outfreq" ; B ; ".txt=" ; Chr(34) ; Work(8) ; Chr(34);
                  Call Nextion
                   'Print "Apparent Power=" ; Work(5)
                   Temp2 = Val(work(9))
                   Temp1 = Str(temp2)
                  Print #1 , "outwatts" ; B ; ".txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Active Power=" ; Work(10)
                   'Print "Load=" ; Work(7) ; "%"
                   Temp2 = Val(work(11))
                   Temp1 = Str(temp2)
                   Temp1 = Temp1 + "%"
                  Print #1 , "load" ; B ; ".txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Buss Volts=" ; Work(Cool
                 ' Print #2 , "status.bussvolts.txt=" + Chr(34) + Work() + Chr(34);
                  'Call Nextion
                   'Print "Battery Volts=" ; Work(9)
                  Print #1 , "battvolts.txt=" ; Chr(34) ; Work(12) ; Chr(34);
                  Call Nextion
                   'Print "Battery Discharge Current=" ; Work(16) ; "Amps"
                   'Print "Battery Current=" ; Work(10) ; "Amps"
                   'are we discharging
                    Temp2 = Val(work(13)) Print
                  'Print "work13" ; Work(13)
                 ' Print



                  Select Case Temp2
                      Case Is > 0
                         Work(13) = Str(temp2)
                         'Work(13) = "+" + Work(13)

                          Print #1 , "battamps" ; B ; ".txt=" ; Chr(34) ; Work(13) ; Chr(34);
                          Call Nextion
                      Case 0
                       Temp2 = Val(work(27))
                       If Temp2 = 0 Then
                          Temp2 = 1
                       End If

                       Work(27) = Str(temp2)
                       Work(27) = "-" + Work(27)
                       Print #1 , "battamps" ; B ; ".txt=" ; Chr(34) ; Work(27) ; Chr(34);
                       Call Nextion



                  End Select



                   'Print "Battery Capacity=" ; Work(11) ; "%"
                   Temp2 = Val(work(14))
                   Temp1 = Str(temp2)
                   Temp1 = Temp1 + "%"
                   Print #1 , "soc.txt=" ; Chr(34) ; Temp1 ; 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"
                   Temp2 = Val(work(15))
                   Temp1 = Str(temp2)
                  Print #1 , "panvolts" ; B ; ".txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                   'Print "Solar Charger Battery Voltage=" ; Work(15) ; "Volts"
                   Temp2 = Val(work(26))
                   Temp1 = Str(temp2)
                   Print #1 , "panlamps" ; B ; ".txt=" ; Chr(34) ; Temp1 ; Chr(34);
                  Call Nextion
                  'this section needs changes!!!!
                  ' A = Mid(work(20) , 1)
                     ' If A = "1" Then
                          'Print "SBU Priority=Yes"
                             '  Else
                          'Print "SBU Priority=No"
                     ' End If
                   'A = Mid(work(20) , 2)
                     ' If A = "1" Then
                         'Print "Configuration Change"
                         ' Else
                         'Print "Configuration No Change"
                      'End If
                    'A = Mid(work(20) , 3)
                     ' If A = "1" Then
                         'Print "Solar Charger Firmware Updated"
                          'Else
                         'Print "Solar Charger Firmware Not Updated"
                      'End If
                     'A = Mid(work(20) , 4)
                      'If A = "1" Then
                        'Print "Load is On"
                          'Else
                        'Print "Load is Off"
                      'End If

                      'A = Mid(work(17) , 6 , 3)
                           'D = Val(work(21))
                      'Select Case D

                            'Case 0                          'single machine

                            'Print "No charging On"

                            'Case 1

                            'Print "Solar charging On"

                            'Case 5

                            'Print "AC charging On"

                            'Case 7

                            'Print "Solar & AC Charging On"

                      'End Select
                            'Print ">>>>>>>>>>>" + Chr(34) + Work(3) + Chr(34)
               Select Case Work(3)

                   Case "P"                                 'POWER ON MODE
                      Temp1 = "POWER ON MODE"

                   Case "S"                                 'STANDBY MODE
                      Temp1 = "STANDBY MODE"

                   Case "L"                                 'LINE MODE

                     Temp1 = "LINE MODE"

                   Case "B"                                 'BATTERY MODE
                     Temp1 = "BATTERY MODE"

                   Case "F"                                 'FAULT MODE
                     Temp1 = "FAULT MODE"

                   Case "H"                                 'POWER SAVING MODE
                     Temp1 = "POWER SAVING MODE"


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

            End If


       End Select

     Else

       Work(1) = "BAD CRC"
       Print #1 , "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 #1 , &HFF ; &HFF ; &HFF
 Waitms 200
 End Sub







Serial0charmatch:

Goto Screenchng


Return




 $include "font8x8.font


The attached HMI file is for the 7inch enhanced
regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Mar 31, 2020 4:21 am    Post subject: Reply with quote

I have a problem with the Nextion wave form component.
It does not remember the data when you change pages.
So I need a buffer that I can push bytes into at one end and they move along the buffer
when its full the bytes keep moving along with the byte at the other end dropping off (lost)
updating the values while not displaying on the nextion.
I can then send the buffer to the display.
I would like some help to create this
This would benefit anyone using the nextion.

Being able to creat 4 buffers is needed as the component can display 4.

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

Bascom Member



Joined: 22 Jun 2004
Posts: 1161
Location: France

france.gif
PostPosted: Tue Mar 31, 2020 2:33 pm    Post subject: FIFO Reply with quote

you want to create FIFO algorithms
there are many examples on the web.
it uses a lot of memory resources because you have to replace the "First" values with the "second" values and so on.
so, for the Nextion, 4 arrays of 255 bytes for 4 slopes

a small examples from Bascomforum.de (write by djmsc)
all values are rotated

Dim Mein_array(25) As Byte
Dim Temp1 As Byte , Temp2 As Byte , I As Byte
Temp1 = Mein_array(1)
For I = 1 To 24
Temp2 = Mein_array(i + 1)
Mein_array(i) = Temp2
Next I
Mein_array(25) = Temp1

JP
Wink

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

Bascom Expert



Joined: 25 Nov 2005
Posts: 131
Location: Graz

austria.gif
PostPosted: Tue Mar 31, 2020 5:35 pm    Post subject: Reply with quote

Other keywords are circular buffer or ring buffer.

Duval JP wrote:
Dim Mein_array(25) As Byte
Dim Temp1 As Byte , Temp2 As Byte , I As Byte
Temp1 = Mein_array(1)
For I = 1 To 24
Temp2 = Mein_array(i + 1)
Mein_array(i) = Temp2
Next I
Mein_array(25) = Temp1

That's something different

_________________
LCD Menu | Proportional Fonts
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Tue Mar 31, 2020 10:34 pm    Post subject: Reply with quote

Thank you for the example.
But the problem is not that I did not work it out its speed
It needs to be very fast
4 x 255 byte buffers
so lots of cycles it needs to be in Assembler
Also the M1284p with 16k of ram may be the CPU to use.

I have it working here.
You can see I tried memcopy but it needs two arrays it does not work on the same array.

Code:

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


$crystal = 16000000                                         ' used crystal frequency
$baud = 1200                                                ' use baud rate
$hwstack = 50
$swstack = 50
$framesize = 50

Dim Ar(255) As Byte
Dim Vr(5) As Byte
Dim J As Byte



Ar(1) = 1
Ar(2) = 2
Ar(3) = 3
Ar(4) = 4
Ar(5) = 5

'J = Memcopy(ar(1) , Ar(2) , 4)
  J = 255

While J > 1
  Ar(j) = Ar(j - 1)
  Decr J

Wend


For J = 1 To 5
Print Ar(j)
Next

End
 
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Wed Apr 01, 2020 6:48 am    Post subject: Reply with quote

Here is a Nextion turned into a data terminal

Regards Paul
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5920
Location: Holland

blank.gif
PostPosted: Wed Apr 01, 2020 8:27 am    Post subject: Reply with quote

ok, that is simple :

Code:
Dim Ar(10) As Byte
'ar(x)=ar(x-1)
Ar(1) = 1
Ar(2) = 2
Ar(3) = 3
Ar(4) = 4
Ar(5) = 5
Loadadr Ar(1) , X                                           'first location
! ldi r24,10 ; size of array
! ldi r25,0
!add r26,r24                ; add size
!adc r27,r25
!movw r30,r26               ; copy to Z
!sbiw r30,1 ; adjust
!lp1000:
!ld r23,-z  ; load byte
!st -x,r23
!sbiw r24,1
!brne lp1000

For J = 1 To 10
 Print Ar(j)
Next

 


the size goes into r24:r25 and you load the start of the array.
it can also be done using only Z :



Code:
Loadadr Ar(1) , Z                                           'first location
! ldi r24,10 ; size of array
! ldi r25,0
!add r30,r24                ; add size
!adc r31,r25
!sbiw r30,1 ; adjust
!lp1000:
!ld r23, -z  ; load byte
!std z+1,r23
!sbiw r24,1
!brne lp1000
 

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog All times are GMT + 1 Hour
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
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