Shop OBEX P1 Docs P2 Docs Learn Events
Transmitting HEX Commands to an OLED display ? — Parallax Forums

Transmitting HEX Commands to an OLED display ?

JMLStamp2pJMLStamp2p Posts: 259
edited 2007-12-09 05:47 in Propeller 1
Hello All,

I am using an OLED-96-Prop to send serial data to an OLED-160 to pull up graphics Pics. out of the SD card. I have got FullDuplexSerial loaded and using the following code. Could someone tell me what the HEX modifier
is so I can make sure that I send HEX to the OLED-160.


PUB Transmit
· data.start(21,20,0,9600)················ 'rx pin = 21 : tx pin = 20 : mode : baud rate
· DELAY.PauseSec(15)
· data.tx(55)·····················'Auto Baud Command
· DELAY.PauseSec(1)

·I need to be transmitting HEX commands·here:

· data.tx(40)
· data.tx(49)
· data.tx(0)
· data.tx(0)
· data.tx(A0)
· data.tx(80)
· data.tx(10)
· data.tx(0)
· data.tx(10)
· data.tx(0)
· data.tx(7)
· data.tx(B)
· data.tx(B8)

Thanks,
JMLStamp2p
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-07 02:01
    You're not so much sending hex commands as much as writing them in your program using hexadecimal. The uOLED just sees 8 bit numbers. If you want to write hex values in your program, use "$" in front of them. In your case, you'd write things like "data.tx($A0)". Decimal values don't have any prefix character while binary numbers use "%" and quaternary numbers (base 4) use "%%". The value $B8 is the same thing as %10111000 or %%2320 or 184.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-07 03:48
    Thanks Mike, I have re-written the code as follows:
    I have sent these same commands via a small Visual Basic program that I wrote to test the Display and it worked great. When I run the same commands through the Prop-96 to the OLED-160 it halts when it sees the Auto Baud command but then does nothing. I can see the serial data on my scope so I know that it is being transmitted and don't understand what is wrong. The data sheet on the OLED-160 says it needs app. 300ms to respond after each commandwith an ack. I sent the commands in VB
    without the delay but maybe the Prop is executing faster. Mike, as you can see I am using pin 20 on the OLED-96-Prop to send the serial data out. I wouldn't assume that this line would not need to be pulled high or low and I am using a 100 ohm resistor
    in series before it gets to the OLED-160. Do you see something that I am doing wrong ? I am running this code in a loop just to monitor the display ...
    Can I use "waitcnt (300)" as a pause for 300 ms between each tx command ? Also,

    ......................................................................................................................
    PUB Transmit
    data.start(21,20,0,9600) 'rx pin = 21 : tx pin = 20 : mode : baud rate

    DELAY.PauseSec(10)
    data.tx($55) 'Auto Baud Command for the OLED-160
    DELAY.PauseSec(5)

    data.tx($40)
    data.tx($49)
    data.tx($0)
    data.tx($0)
    data.tx($A0)
    data.tx($80)
    data.tx($10)
    data.tx($0)
    data.tx($10)
    data.tx($0)
    data.tx($7)
    data.tx($B)
    data.tx($B8)

    DELAY.PauseSec(10)
    OLED.CLS
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-07 03:52
    Mike, should I use mode 2 instead ? Am I inverting the serial output on pin 20 ?
    JMLStamp2p
    John.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-07 05:29
    I don't have any personal experience with the OLED-160 although I have used the OLED-128. The OLED-128 runs nicely at 115300 Baud and uses a mode of %0000. Here are some fragments of the code I used for the OLED-128:
       ser.start(oLEDtx,oLEDrx,%0000,115200)      ' Start display
       waitcnt(clkfreq * 2 + cnt)                 '  Wait two seconds
       ser.rxflush                                '  Flush any junk   
       ser.tx("U")                                '  AutoBaud
       waitAck                                    '  Wait for ACK
       oLEDbkgd(oLEDblack)                        '  Set black background
       ser.tx("F")                                '  Set font
       ser.tx(font8x12)
       waitAck
       ser.tx("O")                                '  Set opaque mode
       ser.tx(opaque)
       waitAck
       ser.tx("E")                                ' Erase screen
       waitAck
       oLEDstart(0,0,font8x12,oLEDgrey)
    
    

    and
    PRI waitAck | t                               ' Wait oLEDwait for ACK from oLED
      t := cnt
      repeat while (cnt - t) < (clkfreq / 1000)* oLEDwait
        if ser.rxtime(oLEDwait) == oLEDack
          return true                             ' Got it, exit with success
        else
          ser.rxflush                             ' Something else, flush all
    
    
    PRI oLEDstart(col,row,font,color)
    '   col : 0-20 in 5x7, 0-15 in 8x8 and 8x12
    '   row : 0-15 in 5x7 and 8x8, 0-9 in 8x12
       ser.tx("s")
       ser.tx(col)
       ser.tx(row)
       ser.tx(font)
       ser.tx(color.byte)
       ser.tx(color.byte[noparse][[/noparse]0])
    
    PRI oLEDfinish
       ser.tx(0)
       waitAck
    
    PRI oLEDbkgd(color) | bkgd
       ser.tx("B")
       ser.tx(color.byte)
       ser.tx(color.byte[noparse][[/noparse]0])
       waitAck 
    
    
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-07 15:42
    Mike,
    Thank You for your code and most of all the comments to the right. It really helps bridge
    the gap from your experience and knowledge in Spin to my lack of it. I will incorperate the "ack" segment of code in my program to see if that makes a difference. I realized last night that there was no need for the in-line resistor since the output of the Prop-96 is at 3.3 volts. As far as the logic state of the Props output pins, are they interneally held Hi or Lo ? I assumed that there is no need of external Pull-up's or Pull-Down resistors, am I right ?

    JMLStamp2p
    John.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-07 15:49
    Mike,
    Is there any reason why I couldn't use Pin 30 "tx pin" of the OLED-96-Prop after the Initialization
    process for serial data out to the OLED-160 ? I really need the user pins "18,19,20 & 21" of the OLED-96 for other task if possible.

    John.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-07 16:10
    Mike,
    I believe that I may have just found my problem. I read where the output state of all Propelleer Pins
    are set low on startup. I assume that I need to use:

    dir[noparse][[/noparse]20] ~~
    outa[noparse][[/noparse]20] ~~

    I understand the OLED-160 needs to see this pin at a High logic state at the start of the serial transmission process. I will try this tonight and see if it makes a difference.
    Thanks for your help,

    JMLStamp2p
    John.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-12-07 18:20
    1) Output pins are held in the state determined by the output register. If the pin is set to input mode (default), it is high impedance and would need a pullup or pulldown to set the default level. In the case of serial output, a pullup sets the line to idle.

    2) Yes you can use pins 30/31 for an ordinary serial channel once your program starts. I do this in uOLED-96-Basic for the "console".

    3) The output pins of the Propeller are set to input (high impedance) mode on reset. Read the datasheet. You'll see that there's a direction and an output register for each cog. They're OR'd together so, if any cog sets a pin to output, it will be an output. If any pin set to output mode has its output register set to a 1 for that pin, then the output will be a high level.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-07 21:07
    Mike,
    I understand, thanks for the help I believe that this will fix my problem.
    JMLStamp2p
    John.
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-08 23:04
    Hello Mike,
    OLED Problem Up-date.

    I am sending the following code to an OLED-160 through a TTL level reciever and all is working fine. Strange, but my input on the recieve line is at a Low logic level on power-up and it works every time. The highlighted code are the commands that the GC provided.They are·loaded in a Visual Basic array and transmitted out the serial port through a matching transmitter.
    My problem is this:
    I am trying to send the same commands out of a OLED-Prop-96, I have the recieve line of the OLED-160 pulled High through a 10K pull-up resistor to prevent a false Auto Baud. On power-up the Display is showing the Flash
    screen, As I monitor the data output of Pin 20 on the OLED-160-Prop "My transmit line to the OLED-160" I see the Auto Baud command being transmitted and the Flash screen haults. After the Auto Baud is recognized
    I wait 3- seconds and I see the commands being sent to the OLED-160 to bring up my graphics Pic. but nothing happens !
    The only differnece that I see is this:
    On the Reciever circuit that is working, my logic High level on the recieve pin to the OLED-160 is at a 5V. On the circuit that is not working High logic level signal is at a 3.6V. From what I understand a High logic level to the display should be Vdd divided by 2 or 2.5V since I am using a 5V supply. Am I understanding this correctly ?

    Should I use a Transistor to amplify the data coming out of my OLED-96-Prop
    to a higher logic level ?

    ....................................................................................................
    Working VB code:
    ....................................................................................................

    Private Sub SkinButton19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SkinButton19.Click

    Dim idx As Integer

    Dim my_array As Byte() = New Byte(14) {&H40, &H49, &H0, &H0, &H80, &H80, &H10, &H0, &H10, &H0, &HB, &H0, &H0, &H0, &H0}

    For idx = 0 To 12 'Display Object from SD card !

    SerialPort1.Write(my_array, idx, 1)

    Next
    End Sub

    ......................................................................................................
    Spin Code that is not working in the OLED-96-Prop:

    Note: The Spin code works attached directly to the serial port on my computer through the USB to Serial adapter.
    ......................................................................................................

    CON
    · _CLKMODE····· = XTAL1 + PLL8X·······················
    · _XINFREQ····· = 8_000_000

    · dSlow········ = 50
    · dFast········ = 20
    ·

    OBJ
    · OLED· : "uOLED-96-Prop_V4"
    · DELAY : "Clock"
    · DATA : "FullDuplexSerial"


    VAR
    · long Stack [noparse][[/noparse]9]
    · byte Byte_Recieved
    ..................................................................................................
    ·
    PUB MAIN
    · 'dira[noparse][[/noparse]20]~~
    · 'outa[noparse][[/noparse]20]~~
    ·
    · DELAY.Init(8_000_000)
    · OLED.InitOLED
    · OLED.CLS
    · Transmit
    · 'REPEAT
    · 'Johns
    ··
    PUB Transmit
    · data.start(21,20,0,9600)················ 'rx pin = 21 : tx pin = 20 : mode : baud rate
    · DELAY.PauseSec(7)
    · data.tx($55)
    · DELAY.PauseSec(3)
    · Johns
    ....................................................................................................
    PUB Johns

    · data.tx($40)·
    · data.tx($49)
    · data.tx($00)
    · data.tx($00)·
    · data.tx($80)
    · data.tx($80)·
    · data.tx($10)·
    · data.tx($00)
    · data.tx($10)·
    · data.tx($00)
    · data.tx($0B)·
    · data.tx($00)
    · data.tx($00)
    · data.tx($00)
    · data.tx($00)
    ··
    ·· DELAY.PauseSec(10)
    ·· OLED.CLS
    ....................................................................................................
  • JMLStamp2pJMLStamp2p Posts: 259
    edited 2007-12-09 05:47
    Mike, I found the problem. I took the following two commands out of my code:
    dira[noparse][[/noparse]20]~~
    outa[noparse][[/noparse]20]~~

    And pulled Pin 20 high through a 10k Resistor and it works every time.
    Thanks,
    JOHN.
Sign In or Register to comment.