Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

GUI-O Counter

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Wed Nov 10, 2021 10:19 pm    Post subject: GUI-O Counter Reply with quote

Here is simple counter for events, made with BASCOM and GUI-O on Android smart phone.

www.gui-o.com
https://play.google.com/store/apps/details?id=com.guio.guioapp

Hardware is Arduino Nano, Bluetooth HC06 and graphic display SSD1306.

In attach is schematic, source code and Youtube video.

https://youtu.be/FNoWI_SyMOg


Enjoy.

Test init procedure.
https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=14855


Code:
'   _____                  _
'  / ____|                | |
' | |     ___  _   _ _ __ | |_ ___ _ __
' | |    / _ \| | | | '_ \| __/ _ \ '__|
' | |___| (_) | |_| | | | | ||  __/ |
'  \_____\___/ \__,_|_| |_|\__\___|_|
'------------------------------------------------------------------------------
' GUI-O V0.11.16 2021-11      www.gui-o.com
'------------------------------------------------------------------------------
' .-----------------------.
' |ATMEGA328 Arduino nano |
' |                       |
' |Clock 16.000000 Hz     |
' |GLCD SSD1306           |
' |gammda 2021-11-09      |
' '-----------------------'
'-Hardware connection----------------------------------------------------------
'********************************************************************
'*     Bluetooth              Arduino Nano            SSD1306       *
'*     .-------.              .-----------.        .-----------.    *
'*     | HC06  |              | Mega 328  |        |           |    *
'*     |       |              |           |        |           |    *
'*     |       |              |           |        |           |    *
'*     |       |              |           |        |     I2C   |    *
'*     |       | TX PortC.1   |           |        '------|----'    *
'*     |       |--------------|           |               |         *
'*     |       | RX PortC.0   |           |   SCL-PortC.5 |         *
'*     '-------'              |           |---------------|         *
'*                            |           |   SCL-PortC.4           *
'*                            |           |                         *
'*                  Input     |           |                         *
'*               o------------|           |                         *
'*                 D3 PinD3   |           |                         *
'*                            '-----------'                         *
'********************************************************************

'$sim

$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 9600
$hwstack = 60
$swstack = 60
$framesize = 60

Config Serialin = Buffered , Size = 120
Open "comc.1:9600,8,n,1" For Output As #1                   'software serial port  Bluetooth
Open "comc.0:9600,8,n,1" For Input As #2

'===============================================================================
' ST1306 LCD I2c 128x64 test example
'===============================================================================
Config Scl = Portc.5                                        ' used i2c pins
Config Sda = Portc.4
Config Twi = 400000                                         ' i2c speed

I2cinit
$lib "i2c_twi.lbx"                                          ' we do not use software emulated I2C but the TWI
$lib "glcdSSD1306-I2C_V2.lib"                               ' override the default lib with this special one

Dim _contrast As Byte                                       ' Contrast value of OLED. [0-255]
'Const Ssd1306_rotate = 0                                    ' Display rotation. [connection cable is lower side = 0, upper side = 1] rotate display 180 degrees.
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"
Cls

'Gettoken LIB declaration (parsing text)----------------------------------------
Dim Sep As Byte
Dim Pozicija As Byte
$lib "GetToken.Lib"
$external Gettoken
Declare Function Gettoken(strinput As String , Byval Bseparator As Byte , Byval Bcount As Byte ) As String

'-Declaration port--------------------------------------------------------------
Config Pind.3 = Input
Set Portd.3
Inp_ Alias Pind.3

'-Logotip picture---------------------------------------------------------------
Cls
Setfont Font8x8
Showpic 0 , 0 , Logoms
Wait 4

'-Define external interrupt INT1------------------------------------------------
Config Int1 = Low Level                                     'Interruption on Falling
On Int1 Count Nosave
Disable Interrupts

'-Variables---------------------------------------------------------------------
Dim Ii As Dword

Dim Iis As Single
Dim Iist As String * 20

Dim Iisf As String * 20

Dim Bt_key As Byte
Dim Znak As String * 15
Dim Bdata As String * 60
Cls

'-Start definition-------------------------------------------------------------
Setfont Font5x12
Lcdat 1 , 1 , "COUNTER"

Gosub Init_gui                                              ' GUI-O initialization

Iisf = Format(iist , "00000000")                            'Counter Zero screen  LCD
Setfont Digital14x24
Lcdat 3 , 1 , Iisf
Print#1 , "@lbd TXT:'" ; Iisf ; "'"                         'Counter Zero smart phone definition
Enable Interrupts
Enable Int1


'-Main Loop--------------------------------------------------------------------

Main:
Do
   Disable Interrupts
   Gosub Read_data                                          ' Read information from software seral port
   Enable Interrupts

Loop
End                                                         'End application


'--Init GUI-o -----------------------------------------------------------------
'=Initialization objects on Smartphone=========================================
Init_gui:
Disable Int1

Print #1 , "@sls 500"
Print #1 , "@cls"
Print #1 , "@clh"
Print #1 , "@clo"
Print #1 , "@gse COD:0 TSC:39"
Print #1 , "@guis BGC:#696969 ASR:0.449671"

Print #1 , "|SORI UID:sori1 HID:sori ORI:2 SEN:0"

Print #1 , "|BSR UID:bsr2 X:50 Y:50 W:90 H:85 VIS:1 ROT:0 RAD:1.5 BGC:#d3d3d3 SBGC:#d3d3d3 FGC:#d3d3d3 SHE:1 BTH:0.5"       'background rectangle

Print #1 , "|BSR UID:bsr3 X:55 Y:40 W:60 H:40 VIS:1 ROT:0 RAD:2 BGC:#000000 SBGC:#000000 FGC:#000000 SHE:1 BTH:0.5"       ' backgroun display
Print #1 , "|LB UID:lbd X:55 Y:40 ALP:0 SHE:1 ROT:0 FGC:#a22200 FSZ:20 FFA:'font2' TXT:'" ; Iisf ; "'"       ' counter digital noumber

Print #1 , "|LB UID:lb0 X:15 Y:15 ALP:0 SHE:1 ROT:0 FGC:#000000 FSZ:10 FFA:'font7' TXT:'Counter'"       ' name of device

Print #1 , "|LB UID:lbt1 X:9 Y:28 ALP:1 SHE:1 ROT:0 FGC:#0350a2 FSZ:7 FFA:'font0' TXT:'Power'"       'Text power
Print #1 , "|LB UID:lbt2 X:9 Y:40.5 ALP:1 SHE:1 ROT:0 FGC:#0350a2 FSZ:7 FFA:'font0' TXT:'Pulse'"       'text pulse

Print #1 , "|LB UID:lblog X:80 Y:88 ALP:1 SHE:1 ROT:0 URL:1 FGC:#0350a2 FSZ:4 FFA:'font0' TXT:'www.gui-o.com'"       'Text GUI-O home page

Print #1 , "|SI UID:si1 X:21 Y:28 W:2.5 VIS:1 ROT:0 BGC:#B0C4DE FGC:#711700 SHE:1 EN:1"       ' LED Power
Print #1 , "|SI UID:si2 X:21 Y:40.5 W:2.5 VIS:1 ROT:0 BGC:#B0C4DE FGC:#711700 SHE:1 EN:0"       'LED Pulse
Print #1 , "|BT UID:bt5 X:80 Y:75 W:8 H:16 SHE:1 ROT:0 RAD:0.5 BGC:#711700 SBGC:#711700 FGC:#FFFFFF FSZ:4 BTH:0 TXT:'RESET' SVAL:'reset'"       'Button reset

Print #1 , "|BT UID:btqt X:13 Y:28 W:10 H:10 SHE:1 ROT:0 RAD:0.5 BGC:#00711700 SBGC:#00711700 FGC:#00FFFFFF FSZ:4 BTH:0 TXT:'Quit app' SVAL:'reset'"       'Button Quit- hidden on text "Counter"



Print #1 , "@hls 200"
Enable Int1
Return


'==============================================================================
'Reading data from serial port - from GUI-O keys (UID names)
Read_data:

  Bt_key = Inkey(#2)
  If Bt_key = "@" Then Input #2 , Bdata Noecho
  Sep = &H20
  Pozicija = 1
  Znak = Gettoken(bdata , Sep , Pozicija)

    If Znak = "bt5" Then                                    'Key Reset counter
      Ii = 0

     Iis = Ii
     Iist = Str(ii)
     Iisf = Format(iist , "00000000")
     Setfont Digital14x24
     Lcdat 3 , 1 , Iisf
     Print#1 , "@lbd TXT:'" ; Iisf ; "'"

     Znak = " "
   End If

   If Znak = "btqt" Then
     Print #1 , "@quitapp"                                  'Quit application
     Znak = " "
   End If

   If Znak = "init" Then                                    'Start key Initialization

      Gosub Init_gui
      Znak = ""

   End If

   Znak = ""
   Bdata = ""
   Enable Int1
Return


'-Procedure for interrupt INT1--------------------------------------------------
 Count:
 Disable Interrupts
 Print #1 , "@si2 EN:1"


     If Inp_ = 0 Then
       Ii = Ii + 1

       While Inp_ = 0
       Wend

     End If


  Iist = Str(ii)
  Iisf = Format(iist , "00000000")
  Setfont Digital14x24
  Lcdat 3 , 1 , Iisf
  Print#1 , "@lbd TXT:'" ; Iisf ; "'"


  Print #1 , "@si2 EN:0"
  Enable Interrupts
 Return

'-EEprom-----------------------------------------------------------------------
R_eep:
 '  Readeeprom Ii , &H10      'In case saving data to EEPROM
Return

'-GLCD fonts / Logo picture----------------------------------------------------
$include "Digital14x24.font"
$include "font5x12.font"
$include "font8x8.font"

Logoms:
   $bgf "Logoh2o.bgf"
'------------------------------------------------------------------------------
Back to top
View user's profile
SirLeslie

Bascom Member



Joined: 17 Aug 2006
Posts: 13
Location: France

france.gif
PostPosted: Sun Nov 14, 2021 1:27 pm    Post subject: Re: GUI-O Counter Reply with quote

matjazs wrote:
Here is simple counter for events, made with BASCOM and GUI-O on Android smart phone.
...


Hi Matjazs,

Nice and clean project (= with many comments), thank you for sharing with us!
If i kindly ask you: is it possible to make the same tutorial for output version? (control pin/output(s) with the smartphone?)

Thank you.
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Mon Nov 15, 2021 4:05 pm    Post subject: Reply with quote

Of course. Communication is two-way.

Maybe you describe in more detail (max frequency, sweep, ...) that we (I) can help.
Explain what kind of device you want to make.
Back to top
View user's profile
SirLeslie

Bascom Member



Joined: 17 Aug 2006
Posts: 13
Location: France

france.gif
PostPosted: Mon Nov 15, 2021 4:56 pm    Post subject: Reply with quote

matjazs wrote:
Of course. Communication is two-way.

Maybe you describe in more detail (max frequency, sweep, ...) that we (I) can help.
Explain what kind of device you want to make.


Thank you for your response.
Just control remote sockets (eg.: garden/external lights) [output(s)], a read back the status of the output (this your great example).
Of course possible to add the powermeter functions/timings/etc. also - but for me better to one simple example... to see/understand the simple rx/tx program lines.

Thanks,

Laszlo
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Mon Nov 15, 2021 8:11 pm    Post subject: Reply with quote

SirLeslie wrote:
matjazs wrote:
Here is simple counter for events, made with BASCOM and GUI-O on Android smart phone.
...


Hi Matjazs,

Nice and clean project (= with many comments), thank you for sharing with us!
If i kindly ask you: is it possible to make the same tutorial for output version? (control pin/output(s) with the smartphone?)

Thank you.



Here is a very simple example: a switch and an LED light.

https://www.youtube.com/watch?v=EN_tJgk79kU

The hardware is an Arduino Nano (but you can use another if you have one)

Five objects are used in the application: (BSR) grey background rechtangle, (LB) Label, (TG) Toggle Switch, (SI) status indicator-LED and (IM) Image. (Advice: Using image object, simply copy "Light.jpg" to your smart phone in directory: Android > Data> com.gui.oapp > files > Pictures)

These objects are prepared in the initialization process (Init_guio), which is sent once from the serial interface (RxTx) via the HC06 bluetooth module.

Code:
'-Init GUIo -------------------------------------------------------------------
Init_guio:
 Print "@cls"
 Print "|BSR UID:gb0 X:50 Y:50 W:100 H:100 VIS:1 ROT:0 RAD:0 BGC:#99A3A4 FGC:#F39C12 SHE:1 BTH:0.5"       'Group BOX
 Print "|LB UID:lb1 X:50 Y:70 FGC:#01F3FE TXT:" ; Chr(34) ; "GUI-O test LED" ; Chr(34)       'Label
 Print "|SI UID:si1 X:50 Y:50"                              'status indicator - LED
 Print "|TG UID:tg1 X:50 Y:60 W:20 H:3"                     'toggle switch
 Print "|IM UID:im1 X:50 Y:20 W:40 H:40 IP:" ; Chr(34) ; "Light.jpg" ; Chr(34)       ' image
Return
'------------------------------------------------------------------------------



After that you can use one ore more parameters together for this objects.

To turn on the light, only the information is read via Rx (serial port) if the TG (toggle switch) is ON or OFF and then the PORT on the controller is turned ON or OFF.
Phone send "
Code:
@tg1 1
" or "
Code:
@tg1 0
" to microcontroller.

We read this string and decide what we do.

Code:
If Bdata = "tg1 1" Then                                     'toggle switch ON
     Set Led
     Print "@si1 EN:1"                                                  'LED ON
     Waitms 300
End If
If Bdata = "tg1 0" Then                                     'toggle switch OFF
     Reset Led
     Print "@si1 EN:0"                                         'LED OFF
     Waitms 300
End If


Attached is the entire Bascom program, schematic and Youtube video. For more detailed information you can read the manual:
https://www.gui-o.com/assets/gui-o_developer_manual.pdf

or ask here on the forum.

Other examples (including Bascom) are on this website:
www.gui-o.com

P.S. You can use also internet connection using ESP8266 module.


Last edited by matjazs on Mon Nov 15, 2021 8:19 pm; edited 2 times in total
Back to top
View user's profile
SirLeslie

Bascom Member



Joined: 17 Aug 2006
Posts: 13
Location: France

france.gif
PostPosted: Mon Nov 15, 2021 8:18 pm    Post subject: Reply with quote

matjazs wrote:

Here is a very simple example:
...
P.S. You can use also internet connection using ESP8266 module.


Simple for you... but now: for me also Wink with your detailed informations.
I wish only "local" control - now, thank you for the suggestion.

Thank you so much!


Laszlo
Back to top
View user's profile Visit poster's website
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Fri Nov 26, 2021 8:30 pm    Post subject: Reply with quote

The counter is now upgraded with the "Hold" button. This means that the counting stops after the button is pressed.
There is also an LED to indicate this feature.

New Bascom code and image are included.
Back to top
View user's profile
matjazs

Bascom Member



Joined: 08 Nov 2016
Posts: 86

PostPosted: Tue Feb 01, 2022 6:40 pm    Post subject: Reply with quote

The counter is now upgraded with the "Offset" button. This means that you can add or remove digits.

New Bascom code, screenshot image and Youtube ScreenRecords from my phone are included.

https://www.youtube.com/watch?v=Gyno8J4-pJc
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here 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