Shop OBEX P1 Docs P2 Docs Learn Events
Interfacing Bs2 with uoled-128-g2 screen — Parallax Forums

Interfacing Bs2 with uoled-128-g2 screen

lwcyblwcyb Posts: 13
edited 2013-07-30 06:49 in BASIC Stamp
Hello,

I'm attempting to interface a BS2 to a 4D uoled-128-g2 1.5" screen, and I'm running into an issue. After successfully making graphics appear on the screen using 4D's developer environment with a visi program, I've moved on to the serial environment so I can begin trying to build a serial program. I set the screen back to default serial mode by clicking the SPE Load button in the 4d developer environment. I'm trying to send the screen serial commands from the BS2 now, but I apparently I am not sending the correct bytes. I've tried a bunch of different commands in the 4D serial commands listing, but none of them are acknowledged by the module, I always get the wrong byte back (not 06). I feel like I'm missing something here, so if anyone has any tips I'd greatly appreciate them.

Here's the BS2 code I'm using to send serial commands to the uoled module:
PAUSE 2000
SEROUT opin, baud, [$55]
GOSUB GetACK
PAUSE 100

GetACK:

SERIN ipin, baud, [Rx]
IF (Rx = $06) THEN
DEBUG "test"
RETURN
ELSE
DEBUG "NAK  ", HEX Rx, CR                      
ENDIF
RETURN

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-26 10:48
    Do you have a link handy to the serial command guide you're using? I can take alook at it, but don't have it handy. I've used the G1, but not the G2.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-26 11:26
    Thanks! I am looking through it right now and the first question I have is did you set the serial parameters in the software for the display to the same as you're using on the BASIC Stamp Module?
  • lwcyblwcyb Posts: 13
    edited 2013-07-26 11:43
    I have the baud rates set to the same speed (4800) if that's what you're talking about?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-26 12:44
    Are you waiting the required 2 seconds after power-up before trying to communicate with it? Also, you're sending $55, but I'm not sure what that will do if it's the first command you send to the board, based on what it is supposed to do.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-26 13:44
    Another thing I just noticed is that it seems the commands start with a 2-byte command followed by the parameters for that command (if any). Have you tried one of the example commands shown in the serial documenation?
  • lwcyblwcyb Posts: 13
    edited 2013-07-29 07:02
    Looks like that was the exact issue!

    I looked over the documentation like you suggested and I don't think $55 is an actual command for the uoled 128. I went into the 4D workshop environment and played around a little with the serial commander tool, which made me realize I wasn't sending complete commands to the screen. Comparing the documentation to the serial commander tool made me realize I was incorrectly reading the documentation - I was missing half of what was needed to be sent to the screen. I was sending the appropriate parameters but I wasn't designating what function of the goldelox "library" the screen was supposed to be accessing. No wonder it wasn't acknowledging my requests :tongue:
  • lwcyblwcyb Posts: 13
    edited 2013-07-29 07:52
    For anyone trying to interface a BS2 with the 4D uoled 128 g2, here's the code that I'm using:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    
    Rx    VAR Byte          'var for received byte
    opin  VAR Byte          'var for TX pin
    ipin  VAR Byte          'var for RX pin
    baud  VAR Word          'var for baud rate
    
    '****************
    'Constants
    '****************
    opin = 8               'TX
    ipin = 7               'RX
    baud = 188             ' baud rate
    
    '****************
    'Conditional code
    '****************
    main:
    DEBUG "begin"
    PAUSE 2500
    SEROUT opin, baud, [$00, $0C, $00, $00]   'Disables screen saver
    PAUSE 100
    SEROUT opin, baud, [$FF, $D7]   'Clears the screen
    GOSUB GetACK
    PAUSE 100
    SEROUT opin, baud, [$FF, $CF, $00, $32, $00, $32, $00, $64, $00, $64, $04, $00] 'Draw Green Rectangle
    PAUSE 100
    SEROUT opin, baud, [$FF, $CF, $00, $19, $00, $19, $00, $32, $00, $32, $F8, $00] 'Draw Red Rectangle
    GOSUB GetACK
    END
    
    GetACK:
    SERIN ipin, baud, [Rx]
    IF (Rx = $06) THEN
    DEBUG "test"
    RETURN
    ELSE
    DEBUG "NAK  ", HEX Rx, CR
    ENDIF
    RETURN
    

    I believe the screen is enabled to 9600 by default, so on a BS2 you should change the baud variable to 84 for the 9600 baud setting. If you've downloaded the 4D environment you can change the baud speed for the device by going to File > Options > Serial.

    The code should draw two rectangles on the screen, one red, one green.

    Data sheet again: http://www.4dsystems.com.au/downloads/Software/4D-Workshop4-IDE/Docs/Serial/GOLDELOX-SPE-COMMAND-SET-REV1.3.pdf
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-07-29 12:04
    I'm glad you got it figured out.
  • lwcyblwcyb Posts: 13
    edited 2013-07-30 06:49
    Thanks for your help Chris!
Sign In or Register to comment.