Menu

Picaxe LCD - help needed

Help
2018-01-23
2018-01-30
1 2 3 > >> (Page 1 of 3)
  • JohanDenRidder

    JohanDenRidder - 2018-01-23

    Picaxe have a serial LCD (and OLED) that needs only 1 wire. This can be a handy device for debugging.
    Anyone got it working with GCB?

    I tried Serprint and Hserprint using a PIC 12F1840 but I can't get it to work.
    Any ideas?

    Kind regards,
    Johan den Ridder

     
    • Anobium

      Anobium - 2018-01-24

      Yes, is the answer. We have serial LCD support and one wire OLED. The demos show how one wire LCD can be achieved.

      I published a onewire K107(K117) LCD support for Serial, I2C and SPI.

      Re the SerPrint and HSerPrint = these should work. If you post your code then a few guys will help figure that out.

       
  • stan cartwright

    stan cartwright - 2018-01-24

    In gcb only one byte sent eg
    SerSend 1, 13
    SerSend 1, 10
    in picaxe a number of bytes
    SEROUT pin,baudmode,(13,10)

     
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    I have a DC-motor that has a Hall sensor attached to its spindle.
    I want to use the signal from the sensor to stabilize the motor to the speed set by the potentiometer.

    I need speeds from 240 to 6000 rpm. At these spindle speeds the sensor gives pulses from 130 to 5 mSec.

    The value from the potentiometer goes from 0 to 255. The formula "SetSpeed = (255-ReadAD(An3))/2" converts this to 127 to 0 which is close enough.
    In the loop the pulse width will be adjusted until SensorSpeed is same as SetSpeed.

    #chip 12F1840
    #define Motor PORTA.2
    #define Potmeter PORTA.4
    #define LED3 PORTA.5
    #define LED5 PORTA.1
    #define Sensor PORTA.0
    
    dir Potmeter In
    dir LED3 Out
    dir LED5 Out
    dir Motor Out
    dir Sensor In
    
    dim SetSpeed as Byte
    dim CurrentSpeed as Byte
    dim SensorSpeed as WORD
    
    'Pin1 5V - pickit p2
    'Pin2 A5 - LED3
    'Pin3 A4 - (An3) POTMETER
    'Pin4 A3 - pickit p1
    'Pin5 A2 - (CCP1) PWM MOTOR
    'Pin6 A1 - pickit p5, LED5
    'Pin7 A0 - pickit p4, Sensor
    'Pin8 0V - pickit p3
    
    'LED A5 (pin2)
    'Potmeter A4 (pin3)
    'PWM output A2 (HPWM Channel1 = CCP1 = RA2 = Pin5)
    
      'POST
      repeat 5
        PulseOut LED3, 50 ms
        PulseOut LED5, 50 ms
        Wait 100 ms
      end Repeat
    
      'Initializing
      Motor = 1
      CurrentSpeed = 178
    '  HPWM 1,10,255-readAD(An3)
      HPWM 1,10,CurrentSpeed
      wait 5 s
    
      'Main
      do
        SetSpeed = (255-ReadAD(An3))/2
    
        'wait for rising edge
        do while Sensor=off
        Loop
        PulseIn Sensor, SensorSpeed, ms
    
        if SensorSpeed < SetSpeed Then
          CurrentSpeed = CurrentSpeed +1
          PulseOut LED5, 25 ms
          wait 100 ms
        end if
    
        if SensorSpeed > SetSpeed Then
          CurrentSpeed = CurrentSpeed -1
          PulseOut LED3, 25 ms
          wait 100 ms
        end if
    
        HPWM 1, 10,CurrentSpeed
      Loop
    
     
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    Since the motor does not behave like expected I need to check the value of the PulseIn command. That's why I connected the serial LCD.

    I tried HSerPrint:

    #chip 12F1840
    #define LED PORTA.1
    
      'USART settings
      #define USART_BAUD_RATE 2400
      #define USART_TX_BLOCKING
    
      'Show message
      Wait 1 s
      HSerPrint "GCBASIC RS232 Test"
    
    do
    loop
    
     

    Last edit: JohanDenRidder 2018-01-24
    • Anobium

      Anobium - 2018-01-24

      Which port do have the serial device connected to?
      What is connection? The device type.   Does it have an inverted serial line?
      Please add the chip the desired clock frequency.

       
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    ...and SerPrint:

    #chip 12F1840
    #define LED PORTA.1
    #define RS232OUT PORTA.5
    
        'Config Software-UART
        #define SendAHigh Set RS232Out ON
        #define SendALow Set RS232Out OFF
        set RS232Out On
    
        'Set up serial connection
        InitSer 1, r2400, 1 + WaitForStart, 8, 1, none, invert
    
    
    wait 1 s
    SerPrint 1, "test text"
    
    do
    loop
    
     

    Last edit: JohanDenRidder 2018-01-24
  • stan cartwright

    stan cartwright - 2018-01-24

    I don't know about lcd but tried sending to terminal? to see motor results..remember to set baud and com port.

     
    • JohanDenRidder

      JohanDenRidder - 2018-01-24

      I have a Pickit3 connected on USB. I don't think it is possible to write to the UART since that function is grayed out.

       
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    With HSerPrint I used Port.0 (pin 7)
    When using SerPrint I had the LCD on PortA.5 (pin 2)

     
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    I tried clock frequencies from 4 to 32 MHZ with command #chip 12F1840, 16
    It made no difference.
    The LCD does print something, but it doesn't make no sense.

    About the polarity, I am not sure if it is inverted, but the LCD works ok on a Picaxe pin using "serout".

     
    • Anobium

      Anobium - 2018-01-24
      'Set chip model:
      #chip 12F1840, 32
      
      'Set internal oscillator to 32MHz (datasheet 5.2.2.6):
      Set OSCCON = b'11110000'
      
      'Config Hardware-UART:
      #define USART_BLOCKING
      #define USART_BAUD_RATE 9600
      
      Do
        HSerPrint "This is a test!"
        HSerPrintCRLF
        Wait 1 s
        Loop
      
       
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    Hi Anobium,

    Your solution prints 4 characters at a time, but they don't make sense.
    The Picaxe display is 2400 baud, so I changed 'define USART_BAUD_RATE 9600' to
    2400. The display now shows 10 characters at a time.

    I tried HSerPrint "AAAAAAAAAA" to see if the characters would be all the same, but they weren't,
    But the are the same at every loop though.

     
    • Anobium

      Anobium - 2018-01-24

      This sounds like older version of Great Cow BASIC - can you tell me the version in use is?

       
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    I am not sure where I can find the version, but I downloaded GCB in november 2017

     
    • Anobium

      Anobium - 2018-01-24

      Compile the source and attach the ASM to the post.

       
  • JohanDenRidder

    JohanDenRidder - 2018-01-24

    Source:

    'Set chip model:
    #chip 12F1840, 32
    
    'Set internal oscillator to 32MHz (datasheet 5.2.2.6):
    Set OSCCON = b'11110000'
    
    'Config Hardware-UART:
    #define USART_BLOCKING
    #define USART_BAUD_RATE 2400
    
    Do
      HSerPrint "AAAAAAAAAA"
      HSerPrintCRLF
      Wait 1 s
      Loop
    

    In test.asm (attachment) it says version 0.98.01 2017-10-27

     

    Last edit: JohanDenRidder 2018-01-24
    • Anobium

      Anobium - 2018-01-24

      I am travelling until Friday. I will look into this when I get back

      Meanwhile, anyone else got this chip?

       
    • Chris Roper

      Chris Roper - 2018-01-25

      I did a copy and paste of your code above, changed the chip to 12LF1840 as I only had the LF part on hand and did a HEX/Flash operation.

      It worked first time.

      I used pin 7 (RA0) as Tx to the Rx of a USB serial converter as I do not have a Serial LCD.

      I think you need to test your electrical hook up as the software works fine.

      Cheers
      Chris

      Edit - for traceability:
      2.9 Sec. Compiler Version: 0.98.01 2017-10-27 Program Memory: 161/4096 words (3.93%) RAM: 10/256 bytes (3.91%) Chip: 12LF1840

       

      Last edit: Chris Roper 2018-01-25
      • Chris Roper

        Chris Roper - 2018-01-25

        At the behest of Anobium I also tested the code without the Oscon hack and at different speeds.
        I can confirm that it works at 32MHz, 16MHz and 4MHz.

        'Set chip model:
        #chip 12LF1840, 4
        
        'Config Hardware-UART:
        #define USART_BLOCKING
        #define USART_BAUD_RATE 2400
        
        Do
          HSerPrint "AAAAAAAAAA"
          HSerPrintCRLF
          Wait 1 s
        Loop
        

        so the line:
        Set OSCCON = b'11110000'
        is not needed, the compiler has already take care of it..

        Cheers
        Chris

         
  • stan cartwright

    stan cartwright - 2018-01-25

    Is it a serial oled? http://www.picaxe.com/docs/axe133.pdf
    Looks like normal 4bit display.
    At least Johan got 10 chars to display. Did it ever work with picaxe?

     
    • JohanDenRidder

      JohanDenRidder - 2018-01-25

      Yes, that's the display that I have. It used to work on Picaxe.

       
  • JohanDenRidder

    JohanDenRidder - 2018-01-25

    I set up a Picaxe with the display and that worked normally.
    Then I hooked up a logic analyzer feeling a bit stupid that I haven't done so right away. One channel on the Picaxe and one channel on the GCB pic (12F1840).

    The analyzer showed right away that the serial signals have different polarities. GCB gives a high signal that is pulled low for data, the Picaxe is the other way around.
    A transistor on the output of the P12F1840 (pin 7) solved that problem.
    Still no readable text though.

    The analyzer also showed that the Picaxe pause between bytes is larger than GCB (1.043 mS vs 0.419 mS)
    So I tried sending pauses between bytes. Now I had normal text for the first time.
    This work around to print "GCBasic RS232 Test" must be optimized of course, but it works:

    #chip 12F1840, 16
    
    'USART settings
    #define USART_BAUD_RATE 2400
    #define USART_TX_BLOCKING
    
    dim Delay as Byte
    Delay=5
    
    wait 1 S
    
    ; clear display (Picaxe specific commands)
    HSerSend(254)
    Wait 50 mS
    HSerSend(1)
    Wait 50 mS
    
    ; move to start of first line (Picaxe specific commands)
    Wait 50 mS
    HSerSend(254)
    Wait 50 mS
    HSerSend(128)
    
    Wait Delay mS
    HSerPrint "G"
    Wait Delay mS
    HSerPrint "C"
    Wait Delay mS
    HSerPrint "B"
    Wait Delay mS
    HSerPrint "A"
    Wait Delay mS
    HSerPrint "S"
    Wait Delay mS
    HSerPrint "I"
    Wait Delay mS
    HSerPrint "C"
    Wait Delay mS
    HSerPrint " "
    Wait Delay mS
    HSerPrint "R"
    Wait Delay mS
    HSerPrint "S"
    Wait Delay mS
    HSerPrint "2"
    Wait Delay mS
    HSerPrint "3"
    Wait Delay mS
    HSerPrint "2"
    Wait Delay mS
    HSerPrint " "
    Wait Delay mS
    HSerPrint "T"
    Wait Delay mS
    HSerPrint "e"
    Wait Delay mS
    HSerPrint "s"
    Wait Delay mS
    HSerPrint "t"
    

    Johan

     

    Last edit: JohanDenRidder 2018-01-25
  • stan cartwright

    stan cartwright - 2018-01-25

    So it works? If so, well done for sorting the problem.
    Is gcb or picaxe not "standard"...or either?

     
  • Chris Roper

    Chris Roper - 2018-01-25

    GCB/PIC complies with the RS232 Standard for timing and polarity, PICKAxe is a soft serial so timing and polarity are software dependent and as it is proprietary, the display it is built to expect that.

    The 12F1840, however, has a hardware invert function on Tx so:

    'Set chip model:
    #chip 12LF1840, 4
    
    
    'Config Hardware-UART:
    #define USART_BLOCKING
    #define USART_BAUD_RATE 2400
    
    SCKP = 1  ' Invert Tx Bit
    
    Do
      HSerPrint "AAAAAAAAAA"
      HSerPrintCRLF
      Wait 1 s
    Loop
    

    Will solve your inversion issue and save you a Transistor.
    The timing issue though is another story.

    Cheers
    Chris

     
1 2 3 > >> (Page 1 of 3)

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.