Menu

Simple GLCD analogue meter

2017-07-10
2017-07-14
1 2 > >> (Page 1 of 2)
  • stan cartwright

    stan cartwright - 2017-07-10

    An analogue meter type display on a 128x64 GLCD measuring 0 to 5 volts. No UDGs.
    https://youtu.be/0hoSBhGgmyc

    ;analogue 5V voltmeter
    #chip mega328p, 16
    #option explicit
    #include <glcd.h>
    #INCLUDE <TRIG2PLACES.H>
    ;
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    GLCDfntDefaultsize=1
    #define ADSpeed LowSpeed
    dir portc.0 in
    dim radius,xcentre,ycentre,xend,old_xend,yend,old_yend as byte
    dim angle,old_angle as word
    xcentre=63
    ycentre=58
    ;draw dial
    GLCDCLS
    box 0,0,127,63
    for radius=144 to 141
      dial
    next radius
    GLCDDrawChar (5,40,asc("0")):GLCDDrawChar (115,40,asc("5"))
    radius=120
    angle=ReadAD(an0)/2
    anglecheck
    ;main
    do
      old_angle=angle
      angle=ReadAD(an0)/2
      anglecheck
      old_xend = xcentre + radius  * sin (old_angle)/255
      old_yend = ycentre - radius  * cos (old_angle)/255
      xend = xcentre + radius  * sin (angle)/255
      yend = ycentre - radius  * cos (angle)/255
    ;erase old needle
      line (xcentre,ycentre,old_xend,old_yend,0)
    ;draw V
      line (55,20,63,36):line (63,36,71,20)
    ;draw new needle
      line (xcentre,ycentre,xend,yend,1)
      wait 10 ms
    loop
    ;end main
    sub plotdial
      xend = 63 + radius  * sin (angle)/255
      yend = 58 - radius  * cos (angle)/255
      pset (xend,yend,1)
    end sub
    ;
    sub dial
      for angle= 296 to 359
        plotdial
      next angle
    ;
      for angle= 0 to 63
        plotdial
      next angle
    end sub
    ;
    sub anglecheck
      if angle>127 then
        angle =angle-127
      else
        angle =296+angle
      end if
    end sub
    
     
  • Anobium

    Anobium - 2017-07-10

    Love it.

    I have adapted for a generic GLCD and changed a few things to use more of Great Cow BASIC - if this acceptable. I would like to move into the demo folders. Is this ok? I can update header to retain copyrights etc

     
    👍
    1
  • stan cartwright

    stan cartwright - 2017-07-10

    Fine by me. You might make it hard to follow if you use too many features though, like Not Tron game. I couldn't follow your version where it was reduced to "if game = true then" a bit :)
    I learn a lot from example/demo code. You can mess about with it and see the results and adapt it for something else. I was inpired by all the arduino projects on youtube and forums. Be fair, you can find arduino demos of most things a micro controller user might make. Either that or pic forums and more C or assembler.
    Posting youtube videos creates maybe a search result so I mention GCB in the title. I should have put ssd1306 in the title so it appeared in a search if someone looked it up.
    I'm trying various electrical/electronic items that appear on amazon or ebay advertised as for arduino or raspberry pi and getting them working with GCB. eg the glcd touch screen feature on ili9341.

     
  • Anobium

    Anobium - 2017-07-10

    Code was attached. Only changes were to glcd, add your name and removal of an errant command.

    Regardingv Touch. Please use ADS7843 library. This is a published library.

     
  • stan cartwright

    stan cartwright - 2017-07-10

    I noticed today.Mine wasn't thoroughly de-bugged. Digital as well is a good idea. It looks nice and simple and the code is simple, it's all under the bonnet. Why did I think for years that include files were pre compiled asm code and so never looked what was inside them? I dunno.
    I looked in ADS7843 library..yes I did :( a few times
    PS I just noticed error but it works?? no error message. Suggests step minus value not needed for step -1

    for radius=144 to 141
      dial
    next radius
    
     

    Last edit: stan cartwright 2017-07-10
  • stan cartwright

    stan cartwright - 2017-07-10

    A picture of meter with your digital display and no change to current needle value.
    Displaying uno 3.3 volt output.

     
  • Keith

    Keith - 2017-07-11

    What a cracking little project Stan, I am going to try to impliment your code onto my 16F18326 and SSD1307display, TinyBootloader and I2C bus. I have no doubt this is going to be another mammoth task. Any tips and pointers would be appreciated..

     
    • Anobium

      Anobium - 2017-07-11

      @Kieth - post your code.. when you have completed... it can go into the release!

       
  • Keith

    Keith - 2017-07-11

    So far So good . No major headaches as yet

     
    • Anobium

      Anobium - 2017-07-11

      BLUE TAC!!!! Nice method.

       
  • Keith

    Keith - 2017-07-11

    Oh Wow.. That would be an honour indeed Sir.!!!!

     
  • stan cartwright

    stan cartwright - 2017-07-11

    Hi Keith. They're interesting displays and GCB makes them so easy to use. The ILI9341 touch glcd with sd card slot is <£5 and better to experiment with-more pixels and colour. spi is only 4 wires.
    Have fun :)
    ps..just enough ram :)

     

    Last edit: stan cartwright 2017-07-11
    • Keith

      Keith - 2017-07-12

      I have ordered one of Fleabay £3.83 inc shipping from China something else to play around with - Thanks

       
  • Keith

    Keith - 2017-07-11

    Video of Project
    https://youtu.be/QRfyIjr72MM

    ;;;;Analogue 5V voltmeter by Stan Cartwright.
    ;;; Modified for 16F18326, GLCD SSD 1306, TinyBootloader & I2C Bus
    ;;; The GLCD SSD1307 is connected to the I2C Bus CLK & DAT as is an
    ;;; I2CEEPROM for further development.

    The code as attached

     
  • Keith

    Keith - 2017-07-11

    @ Stan. Hope I have done you justice with my offerings old friend.

    Did you publish the code ammendment for the digital readout as in your image SAM1670.jpg?

     
  • stan cartwright

    stan cartwright - 2017-07-11

    Kieth, Anobiwan posted multiply adc by 100 and scale and str code but I didn't write that but I could do it totally different so avoiding plagueism :) and post that cos I didn't think off it first :)
    Nice the way he did it by scaling and converting to str then testing chrs for decimal point. A challenge
    hint:- 0 to 255 analogue is 0 to 5V
    255*100=25000 divide by 5=5100
    25500/51=500
    25400/51=498 point 498
    some where getting I am

     

    Last edit: stan cartwright 2017-07-11
  • stan cartwright

    stan cartwright - 2017-07-11

    OK Keith, I sorted it for DVM different to Anobium's method. Two more vars and extra code. Cut and paste to your code. PS youtube didn't open your video for me :(
    Do it justice by using bits for your own thing, I do with other's code. Good way to learn. no ascii 184

    ;analogue 5V voltmeter and DVM
    #chip mega328p, 16
    #option explicit
    #include <glcd.h>
    #INCLUDE <TRIG2PLACES.H>
    ;
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    GLCDfntDefaultsize=1
    #define ADSpeed LowSpeed
    dir portc.0 in
    dim radius,xcentre,ycentre,xend,old_xend,yend,old_yend as byte
    dim angle,old_angle,adcval as word
    dim volts as string * 4
    xcentre=63
    ycentre=58
    ;draw dial
    GLCDCLS
    box 0,0,127,63
    for radius=144 to 141
      dial
    next radius
    GLCDDrawChar (5,40,asc("0")):GLCDDrawChar (115,40,asc("5"))
    radius=120
    angle=ReadAD(an0)/2
    anglecheck
    ;main
    do
      old_angle=angle
    ;----------------- DVM my stylee :)
      adcval=ReadAD(an0) ;!!! new var
      angle=adcval/2
    ;
      adcval=adcval*100
      adcval=adcval/51
      volts=str(adcval) ;!!!-new var
      if adcval<100 then
        volts="0."+volts
      else
        volts=left(volts,1)+"."+mid(volts,2,2)
      end if
    ;-----------------
      anglecheck
      old_xend = xcentre + radius  * sin (old_angle)/255
      old_yend = ycentre - radius  * cos (old_angle)/255
      xend = xcentre + radius  * sin (angle)/255
      yend = ycentre - radius  * cos (angle)/255
    ;erase old needle
      line (xcentre,ycentre,old_xend,old_yend,0)
    ;draw V
      line (55,20,63,36):line (63,36,71,20)
    ;draw new needle
      line (xcentre,ycentre,xend,yend,1)
      GLCDPrint (0,53,volts) ;!!! new-print Voltage. lower V and print above
      wait 10 ms
    loop
    ;end main
    sub plotdial
      xend = 63 + radius  * sin (angle)/255
      yend = 58 - radius  * cos (angle)/255
      pset (xend,yend,1)
    end sub
    ;
    sub dial
      for angle= 296 to 359
        plotdial
      next angle
    ;
      for angle= 0 to 63
        plotdial
      next angle
    end sub
    ;
    sub anglecheck
      if angle>127 then
        angle =angle-127
      else
        angle =296+angle
      end if
    end sub
    
     

    Last edit: stan cartwright 2017-07-11
  • stan cartwright

    stan cartwright - 2017-07-12

    Keith, I dunno how you program your pics that disagrees with you. I use pickit2 and configure the GCB pic prog tool and it's as easy as arduino with bootloader. The in-circuit is a cap,resistor and diode on microchip info. It's so simple when you're aware of it. I was flashing pic hex files and using Xloader for mega328 before I twigged. ;)

     
    • Keith

      Keith - 2017-07-12

      Not quite sure I follow what you mean here Stan, the 16F18326 is an extremely versatile little device with a 32Mhz clock, 28Kb of Flash memory, 2Kb of SRAM and 256B of EEPROM. On the negative side, it is a right faff on programmed with the conventional PICKit as you need to use MPLAB ICE, however using the TinyBootloader, it’s a breeze.

      I use Atmel Studio and an AVRDragon to program ATtiny devices.

      I don’t want to know anything about ‘Arduino’ is he an Italian Ice Cream Man from Venice !

       

      Last edit: Keith 2017-07-12
  • stan cartwright

    stan cartwright - 2017-07-12

    Looks like Anobium's DVM but his doesn't update anything if the input hasn't changed.
    uno 3.3v out again. results is usually 3.29..flickers

     

    Last edit: stan cartwright 2017-07-12
  • Chris Roper

    Chris Roper - 2017-07-12

    Looks great Stan,

    To extend the functionality even further how about adding Average and Peak Values to the Left and Right of the pivot point. That would then need a display reset input to the micro.

    Cheers
    Chris

     
  • stan cartwright

    stan cartwright - 2017-07-12

    Keith, I looked up 16F18326 and thought it said 1024 ram. I didn't know it was a job to prog either. I suppose I'll have to use tiny boot loader and usb to serial eventually. I bought a 18f2550 and 18f2650. One has usb but I haven't tried it.
    Chris, I was just testing trig but for a VU meter then peak hold with second needle for 1 second easyish. It's easy to convert to something else. I thought of a "radar" display using a distance sensor. Also how to move a point from the x/ycentre to the x/yend adapting the line draw routine if you follow how a line is drawn. Dunno why though :)

     
  • stan cartwright

    stan cartwright - 2017-07-12

    Last post on this project, time of flight range finder arrived today.
    Anobiums version did not update needle or volts unless it had changed so the needle doesn't flicker.
    This final code does that. (is it different Anobium?) I also fixed the 0.0x error. It was 0.x.
    The pot is noisy. https://youtu.be/d51PTF8Boh0

    ;analogue 5V voltmeter and DVM. DVM and update display on volt change idea by Anobium
    #chip mega328p, 16
    #option explicit
    #include <glcd.h>
    #INCLUDE <TRIG2PLACES.H>
    ;
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    GLCDfntDefaultsize=1
    #define ADSpeed LowSpeed
    dir portc.0 in
    dim radius,xcentre,ycentre,xend,old_xend,yend,old_yend as byte
    dim angle,old_angle,adcval as word
    dim volts as string * 4
    xcentre=63
    ycentre=58
    ;draw dial
    GLCDCLS
    box 0,0,127,63
    for radius=144 to 141
      dial
    next radius
    GLCDDrawChar (5,40,asc("0")):GLCDDrawChar (115,40,asc("5"))
    radius=120
    angle=0
    anglecheck
    ;need to draw needle first time
    xend = xcentre + radius  * sin (angle)/255
    yend = ycentre - radius  * cos (angle)/255
    line (xcentre,ycentre,xend,yend,1)
    ;----- start main
    do
      old_angle=angle
    ;----------------- DVM my stylee :)
      adcval=ReadAD(an0)
      angle=adcval/2
    ;
      adcval=adcval*100
      adcval=adcval/51
      volts=str(adcval)
      if adcval<10 then
        volts="0.0"+left(volts,1,1)
        goto volt_format_done
      end if
      if adcval<100 then
        volts="0."+mid(volts,1,2)
      else
        volts=left(volts,1,1)+"."+mid(volts,2,2)
      end if
      volt_format_done:
    ;-----------------
      anglecheck
      old_xend = xcentre + radius  * sin (old_angle)/255
      old_yend = ycentre - radius  * cos (old_angle)/255
      xend = xcentre + radius  * sin (angle)/255
      yend = ycentre - radius  * cos (angle)/255
      if old_angle<>angle then ;-- update screen if volts has changed
    ;erase old needle
        line (xcentre,ycentre,old_xend,old_yend,0)
    ;draw V
        line (55,23,63,39):line (63,39,71,23)
    ;print volts
        GLCDPrint (50,9,volts,1) ;volts is already a string so just print it.
    ;draw new needle
        line (xcentre,ycentre,xend,yend,1)
      end if
      wait 22 ms ; needle is stable at this, try different
    loop
    ;----- end main
    sub plotdial
      xend = 63 + radius  * sin (angle)/255
      yend = 58 - radius  * cos (angle)/255
      pset (xend,yend,1)
    end sub
    ;
    sub dial
      for angle= 296 to 359
        plotdial
      next angle
    ;
      for angle= 0 to 63
        plotdial
      next angle
    end sub
    ;
    sub anglecheck
      if angle>127 then
        angle =angle-127
      else
        angle =296+angle
      end if
    end sub
    
     

    Last edit: stan cartwright 2017-07-12
  • stan cartwright

    stan cartwright - 2017-07-13

    Thought I posted edit. This works in front of me at turn on with any input 0 to 5V.
    Anobium pointed out errors I didn't see. Sorry,doh. Please test.

    ;analogue 5V voltmeter and DVM
    #chip mega328p, 16
    #option explicit
    #include <glcd.h>
    #INCLUDE <TRIG2PLACES.H>
    ;
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA
    HI2CMode Master
    #define GLCD_TYPE GLCD_TYPE_SSD1306
    #define GLCD_I2C_Address 0x78
    GLCDfntDefaultsize=1
    #define ADSpeed LowSpeed
    dir portc.0 in
    dim radius,xcentre,ycentre,xend,old_xend,yend,old_yend as byte
    dim angle,old_angle,adcval as word
    dim volts as string * 4
    xcentre=63
    ycentre=58
    ;draw dial
    GLCDCLS
    box 0,0,127,63
    for radius=144 to 141
      dial
    next radius
    GLCDDrawChar (5,40,asc("0")):GLCDDrawChar (115,40,asc("5"))
    radius=120
    angle=1 ;ReadAD(an0)/2
    anglecheck
    ;main
    do
      old_angle=angle
    ;--- DVM
      adcval=ReadAD(an0)
      angle=adcval/2
    ;
      adcval=adcval*100
      adcval=adcval/51
      volts=str(adcval)
      if adcval<10 then
        volts="0.0"+left(volts,1,1)
        goto volt_format_done
      end if
      if adcval<100 then
        volts="0."+mid(volts,1,2)
      else
        volts=left(volts,1,1)+"."+mid(volts,2,2)
      end if
      volt_format_done:
    ;---
      anglecheck
      old_xend = xcentre + radius  * sin (old_angle)/255
      old_yend = ycentre - radius  * cos (old_angle)/255
      xend = xcentre + radius  * sin (angle)/255
      yend = ycentre - radius  * cos (angle)/255
      if old_angle<>angle then ;-- update screen if volts has changed
    ;   erase old needle
        line (xcentre,ycentre,old_xend,old_yend,0)
    ;   draw V
        line (55,22,63,38):line (63,38,71,22)
    ;   print new voltage
        GLCDPrint (50,10,volts,1) ;print Voltage
    ;   draw new needle
        line (xcentre,ycentre,xend,yend,1)
        wait 20 ms
      end if
    loop
    ;end main
    sub plotdial
      xend = 63 + radius  * sin (angle)/255
      yend = 58 - radius  * cos (angle)/255
      pset (xend,yend,1)
    end sub
    ;
    sub dial
      for angle= 296 to 359
        plotdial
      next angle
    ;
      for angle= 0 to 63
        plotdial
      next angle
    end sub
    ;
    sub anglecheck
      if angle>127 then
        angle =angle-127
      else
        angle =296+angle
      end if
    end sub
    
     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.