Cheap I2C OLED display with 08M2

hippy

Technical Support
Staff member
Wonder if there is any way of making a converter picaxe i2c or serial to SMB with extra components??
Probably. And, if it is, it should be possible to do direct SMB from the PICAXE you have.

As said earlier it may be that what the chip is expecting is simply something which the PICAXE cannot do with HI2C commands but can be solved by bit-banging I2C. I will see if I can find code for doing that.
 

hippy

Technical Support
Staff member
This might work but untested -
Code:
#Picaxe 20M2
#Terminal 4800
#No_Data

Symbol SDA = B.5 : Symbol SDApin = pinB.5
Symbol SCL = B.7 : Symbol SCLpin = pinB.7

Do
  Input SCL ; SCL = 1
  Input SDA ; SDA = 1
  Pause 3000
  SerTxd( CR, LF )

  Gosub StartBit
  b0 = 0x16 : Gosub SendByte
  b0 = 0x20 : Gosub SendByte
  b0 = 21   : Gosub ReadBytes
  Gosub StopBit
  SerTxd("Manufacturer=") : b0=21 : Gosub ShowText

  Gosub StartBit
  b0 = 0x16 : Gosub SendByte
  b0 = 0x21 : Gosub SendByte
  b0 = 21   : Gosub ReadBytes
  Gosub StopBit
  SerTxd("Device=") : b0=21: Gosub ShowText

  Gosub StartBit
  b0 = 0x16 : Gosub SendByte
  b0 = 0x22 : Gosub SendByte
  b0 = 5    : Gosub ReadBytes
  Gosub StopBit
  SerTxd("Chemistry=") : b0=5: Gosub ShowText

  ; Day + Month*32 + (Year–1980)*512
  Gosub StartBit
  b0 = 0x16 : Gosub SendByte
  b0 = 0x18 : Gosub SendByte
  b0 = 2    : Gosub ReadBytes
  Gosub StopBit
  w0 = b1 * 256 + b2
  w1 = w0 & 31
  w2 = w0 / 32 & 15
  w3 = w0 / 512 + 1980
  SerTxd("Date=",#w3,"-",#w2,"-",#w1)
  w0 = b0 * 256 + b1
  w1 = w0 & 31
  w2 = w0 / 32 & 15
  w3 = w0 / 512 + 1980
  SerTxd(" or ",#w3,"-",#w2,"-",#w1, CR, LF)

Loop

ShowText:
  bPtr = 1
  Do
    b27 = @bPtrInc
    If b27 >= 0x20 And b27 <= 0x7E Then
      SerTxd( b27 )
    Else
      SerTxd( "<", #b27, ">" )
    End If
  Loop Until bPtr > b0
  SerTxd( CR, LF )
  Return

StartBit:
  Input SCL ; SCL = 1
  Input SDA ; SDA = 1
  Low   SDA ; SDA = 0
  Low   SCL ; SCL = 0
  Return

StopBit:
  Low   SCL ; SCL = 0
  Low   SDA ; SDA = 0
  Input SCL ; SCL = 1
  Input SDA ; SDA = 1
  Return

SendByte:
  bit7 = bit7 : Gosub SendBit
  bit7 = bit6 : Gosub SendBit
  bit7 = bit5 : Gosub SendBit
  bit7 = bit4 : Gosub SendBit
  bit7 = bit3 : Gosub SendBit
  bit7 = bit2 : Gosub SendBit
  bit7 = bit1 : Gosub SendBit
  bit7 = bit0 : Gosub SendBit
  Gosub ReadAck
  Return

SendBit:
  Low   SCL   ; SCL = 0
  If bit7 = 0 Then
    Low   SDA ; SDA = 0
  Else
    Input SDA ; SDA = 1
  End If
  Input SCL   ; SCL = 1
  Do : Loop Until SCLpin = 1
  Low   SCL   ; SCL = 0
  Return

ReadBytes:
  b27  = b0
  bPtr = 1
  Do
    Gosub ReadByte : @bPtrInc = b0
    b27 = b27 - 1
  Loop Until b27 = 0
  Return

ReadByte:
  Gosub ReadBit : bit7 = bit0
  Gosub ReadBit : bit6 = bit0
  Gosub ReadBit : bit5 = bit0
  Gosub ReadBit : bit4 = bit0
  Gosub ReadBit : bit3 = bit0
  Gosub ReadBit : bit2 = bit0
  Gosub ReadBit : bit1 = bit0
  Gosub ReadBit : bit0 = bit0
  Gosub ReadAck
  Return

ReadBit:
  Low   SCL ; SCL = 0
  Input SDA
  Input SCL ; SCL = 1
  Do : Loop Until SCLpin = 1
  bit0 = SDApin
  Low   SCL ; SCL = 0
  Return

ReadAck:
  Low   SCL ; SCL = 0
  Input SDA
  Input SCL ; SCL = 1
  Do : Loop Until SCLpin = 1
  If SDApin = 1 Then
    SerTxd( "NAK Error", CR, LF)
  End If
  Low   SCL ; SCL = 0
  Low   SDA ; SDA = 0
  Return
 

tecnition_ted

New Member
Hi Hippy
Tried code and this was the reply through serial.
I am also trying to get more information from the manufacture but TI are large and usually don't come up with the answer you asked them for

NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
Manufacturer=<255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255>
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
Device=<255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255><255>
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
NAK Error
Chemistry=<255><255><255><255><255>
NAK Error
NAK Error
NAK Error
NAK Error
Date=2107-15-31 or 2107-15-31
 

tecnition_ted

New Member
something interesting:

changed the original code used to read the BQ chip eeprom
to below. Just working on voltage at the moment. I now seem to get part of the correct volts (see pic) but the last two digest are incorrect maybe backwards??? or in wrong order ?? The actual battery voltage is around 7610 last two digest moving as normal

Code:
main:
i2cslave 0x16, i2cslow, i2cbyte                
readi2c 0x09,(b8,b9)                ; Read volt from eeprom
;readi2c 0x09,(b9)                ; Read volt from eeprom

readi2c 0x0E,(b10)            ; Read SOC from eeprom
;readi2c 0x10,(b11)            ; Read SOC from eeprom

readi2c 0x11,(b12)            ; Read time till empty mins from eeprom
;readi2c 0x17,(b13)            ; Read time till empty mins eeprom
debug                        ;
 

Attachments

hippy

Technical Support
Staff member
NAK Error
Manufacturer=<255><255><255><255><255> ...
That indicates nothing is being read, the device isn't responding. Or there's a bug in my code.

I now seem to get part of the correct volts (see pic) but the last two digest are incorrect maybe backwards??? or in wrong order ?? The actual battery voltage is around 7610 last two digest moving as normal
What does "7610" mean, where is that coming from, and what two digits are incorrect, may be in wrong order ?

Things will be much easier to follow if you simplify your program, cut all the cruft out, just work with the raw data ...
Code:
#terminal 4800
i2cslave 0x16, i2cslow, i2cbyte                
do
  readi2c 0x09,(b1,b0)                ; Read volt from eeprom
  sertxd( "b1=", #b1, TAB, "b0=", #b0, TAB, "w0=", #w0, CR, LF )
  pause 500
loop
 

tecnition_ted

New Member
Looking at the BQstudio tool the volts are correct but the last two digit's seem to bounce around a bit. It could be BQ studio filters the results slightly as they also seem to change up and down.. I have the SOC reading correct now also with the address 0x16 even though the chip is supposed to be on 0x17
 

tecnition_ted

New Member
I understand to work with raw data but I couldn't have come up with the code you have without you showing, I understand how it works but don't have all the syntax knowledge yet so have been taking parts of code from the main i2c code that works and I understand and bunching it together to try to get the picaxe to do what i want it to do.

I will get there!

It appears that the total code below works so far.

Code:
symbol counter = w0
symbol subcounter = b2
symbol fontlookup = b3
symbol pixels = b4
symbol displaybank = b5
symbol Volt = w4
symbol SOC = w5
symbol timetillemptymins = w6
symbol bTmp = w7
symbol bTemp = w8


; save Font codes in EEPROM

eeprom 0,(124,130,130,130,124)       ; 0 (ASCII 48)
eeprom 5,(136,132,254,128,128)       ; 1
eeprom 10,(196,162,162,146,140)       ; 2
eeprom 15,(68,130,146,146,108)       ; 3
eeprom 20,(48,40,36,254,32)               ; 4
eeprom 25,(110,138,138,138,114)       ; 5
eeprom 30,(124,146,146,146,100)       ; 6
eeprom 35,(2,2,2,2,254)                   ; 7
eeprom 40,(108,146,146,146,108)       ; 8
eeprom 45,(30,18,18,18,254)       ; 9 (ASCII 57)
eeprom 50,(254,18,18,18,254)       ; A (ASCII 65)
eeprom 55,(254,146,146,146,108)       ; B
eeprom 60,(254,130,130,130,130)       ; C
eeprom 65,(254,130,130,68,56)       ; D
eeprom 70,(254,146,146,146,130)       ; E
eeprom 75,(254,18,18,18,2)           ; F
eeprom 80,(254,130,130,146,242)       ; G
eeprom 85,(254,16,16,16,254)       ; H
eeprom 90,(130,130,254,130,130)       ; I
eeprom 95,(226,130,254,2,2)       ; J
eeprom 100,(254,16,40,68,130)       ; K
eeprom 105,(254,128,128,128,128)       ; L
eeprom 110,(254,2,254,2,254)       ; M
eeprom 115,(254,4,56,64,254)       ; N
eeprom 120,(254,130,130,130,254)       ; O
eeprom 125,(254,18,18,18,12)       ; P
eeprom 130,(124,130,162,66,188)       ; Q
eeprom 135,(254,18,50,82,140)       ; R
eeprom 140,(222,146,146,146,246)       ; S
eeprom 145,(2,2,254,2,2)           ; T
eeprom 150,(126,128,128,128,126)       ; U
eeprom 155,(30,96,128,96,30)       ; V
eeprom 160,(254,128,254,128,254)       ; W
eeprom 165,(198,40,16,40,198)       ; X
eeprom 170,(6,8,240,8,6)           ; Y
eeprom 175,(194,162,146,138,134)       ; Z (ASCII 90)





initialise:
; initialise i2c for display (ID 0x78) and then send power up instructions
                    
hi2csetup i2cmaster,$78,i2cfast,i2cbyte    
hi2cout 0x80,(0xAE,0x00,0x00,0xB0,0x20,0x00,0xD5,0x80,0xA8,0x1F,0xD3,0x00,0x8D, _
0x14,0xA1,0x00,0xC8,0xDA,0x02,0x81,0xCF,0xD9,0xF1, 0xDB,0x30,0xA4,0xA6)

gosub sendtodisplay             ; send 4 blank lines to clear display
let displaybank = 0             ; flag rows 0-3 for display
hi2cout 0x80,(0xAF)             ; turn display on


main:
i2cslave 0x16, i2cslow, i2cbyte                

readi2c 0x09,(b8,b9)                ; Read volt from eeprom
readi2c 0x0d,(b10)                  ; Read SOC from eeprom
readi2c 0x11,(b12,b13)            ; Read time till empty mins from eeprom

debug                        ; Show result


hi2csetup i2cmaster,$78,i2cfast,i2cbyte; 

; Insert your programme code here and then poke 28-91 with message to be displayed
;data to send to display (4 * 16)

poke 28,"T","i","m","e"," ","l","e","f","t"," "
bTmp = timetillemptymins / 1000 // 10 + "0" : Poke 38, bTmp
bTmp = timetillemptymins / 100  // 10 + "0" : Poke 39, bTmp
bTmp = timetillemptymins / 10   // 10 + "0" : Poke 40, bTmp
bTmp = timetillemptymins        // 10 + "0" : Poke 41, bTmp
poke 42," "," "
poke 44," "," ","V","o","l","t"," " ; 
bTmp = Volt / 1000 // 10 + "0" : Poke 51, bTmp
bTmp = Volt / 100  // 10 + "0" : Poke 52, bTmp
bTmp = Volt /  10  // 10 + "0" : Poke 53, bTmp
bTmp = Volt        // 10 + "0" : Poke 54, bTmp
poke 55," "," "," "," "," "
poke 60," "," ","S","o","c"," "," "
bTmp = SOC / 1000 // 10 + "0" : Poke 67, bTmp
bTmp = SOC / 100  // 10 + "0" : Poke 68, bTmp
bTmp = SOC / 10   // 10 + "0" : Poke 69, bTmp
bTmp = SOC        // 10 + "0" : Poke 70, bTmp
poke 71," "," "," "," "," "
poke 76," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "

displaybank = 1 - displaybank         ; toggle lines to display
gosub sendtodisplay             ; load message to display memory and point display at it

; Insert any further code you require here
    




goto main

sendtodisplay:                 ; sends characters in memory locations 28-91 to the display
for counter = 28 to 91
    PEEK counter, fontlookup     ; load character to output
    select case fontlookup
        case 48 to 57                            ; 0-9
            fontlookup = fontlookup - 48 * 5
        case 65 to 90                            ; A-Z
            fontlookup = fontlookup -65 * 5 + 50
        case 97 to 122                            ; a-z output as A-Z
            fontlookup = fontlookup - 97 * 5 + 50
        
        else
            fontlookup = 244     ; all other characters will display a blank
    endselect                    
    hi2cout 0x40,(0)             ; one blank column
    for subcounter = 0 to 4
        read fontlookup, pixels        
        hi2cout 0x40,(pixels)     ; followed by 5 columns per character
        fontlookup = fontlookup + 1
    next subcounter
    hi2cout 0x40,(0,0)         ; two blank columns
next counter                 ; this completes the 8x8 character output
If displaybank = 0 then
    hi2cout 0x80,(0x40)         ; point display to lines 0-3 of display memory
    else hi2cout 0x80,(0x60)     ; point display to lines 4-7 of display memory
Endif
return
 

hippy

Technical Support
Staff member
I have the SOC reading correct now also with the address 0x16 even though the chip is supposed to be on 0x17
The address is definitely 0x16 by default, according to page 77 of -

http://www.ti.com/lit/ug/sluubc1d/sluubc1d.pdf

"The bq40z50-R1 SMBus address (default 0x16) can be changed. The target address should be programmed in Address and the 2’s complement of that value should be programmed in Address Check.

The bq40z50-R1 will check these values upon exit from POR, and if the two data flash values are not valid or the programmed address is 0x00 or 0xFF, then the device defaults to 0x16".

Page 126 clarified the data format and 16-bit signed or unsigned is sent as LSB first, MSB second.

Anyway it's good to see that it's now working. Not sure why it did not earlier.
 
Last edited:

tecnition_ted

New Member
here is one if I use the attached code with a 20m2 all is OK. If i use a 08M2 then the i2c does not seem to read as I get the same read from the I2c all the time. If I remove the serial code it works ok with an i2c oel any ideas?

Code:
symbol counter = w0
symbol subcounter = b2
symbol fontlookup = b3
symbol pixels = b4
symbol displaybank = b5
symbol Volt = w4
symbol SOC = w5
symbol timetillemptymins = w6
symbol bTmp = w7



; save Font codes in EEPROM

eeprom 0,(124,130,130,130,124)       ; 0 (ASCII 48)
eeprom 5,(136,132,254,128,128)       ; 1
eeprom 10,(196,162,162,146,140)       ; 2
eeprom 15,(68,130,146,146,108)       ; 3
eeprom 20,(48,40,36,254,32)               ; 4
eeprom 25,(110,138,138,138,114)       ; 5
eeprom 30,(124,146,146,146,100)       ; 6
eeprom 35,(2,2,2,2,254)                   ; 7
eeprom 40,(108,146,146,146,108)       ; 8
eeprom 45,(30,18,18,18,254)       ; 9 (ASCII 57)
eeprom 50,(254,18,18,18,254)       ; A (ASCII 65)
eeprom 55,(254,146,146,146,108)       ; B
eeprom 60,(254,130,130,130,130)       ; C
eeprom 65,(254,130,130,68,56)       ; D
eeprom 70,(254,146,146,146,130)       ; E
eeprom 75,(254,18,18,18,2)           ; F
eeprom 80,(254,130,130,146,242)       ; G
eeprom 85,(254,16,16,16,254)       ; H
eeprom 90,(130,130,254,130,130)       ; I
eeprom 95,(226,130,254,2,2)       ; J
eeprom 100,(254,16,40,68,130)       ; K
eeprom 105,(254,128,128,128,128)       ; L
eeprom 110,(254,2,254,2,254)       ; M
eeprom 115,(254,4,56,64,254)       ; N
eeprom 120,(254,130,130,130,254)       ; O
eeprom 125,(254,18,18,18,12)       ; P
eeprom 130,(124,130,162,66,188)       ; Q
eeprom 135,(254,18,50,82,140)       ; R
eeprom 140,(222,146,146,146,246)       ; S
eeprom 145,(2,2,254,2,2)           ; T
eeprom 150,(126,128,128,128,126)       ; U
eeprom 155,(30,96,128,96,30)       ; V
eeprom 160,(254,128,254,128,254)       ; W
eeprom 165,(198,40,16,40,198)       ; X
eeprom 170,(6,8,240,8,6)           ; Y
eeprom 175,(68,32,16,8,68)       ; Z (ASCII 90)
eeprom 180,(194,162,146,138,134)       ; %

Pause 30
serout C.4,N2400,(254,1) ; Clear serial display 
Pause 30


initialise:
; initialise i2c for display (ID 0x78) and then send power up instructions
                    
hi2csetup i2cmaster,$78,i2cfast,i2cbyte    
hi2cout 0x80,(0xAE,0x00,0x00,0xB0,0x20,0x00,0xD5,0x80,0xA8,0x1F,0xD3,0x00,0x8D, _
0x14,0xA1,0x00,0xC8,0xDA,0x02,0x81,0xCF,0xD9,0xF1, 0xDB,0x30,0xA4,0xA6)

gosub sendtodisplay             ; send 4 blank lines to clear display
let displaybank = 0             ; flag rows 0-3 for display
hi2cout 0x80,(0xAF)             ; turn display on


main:
i2cslave 0xAA, i2cfast, i2cbyte                
readi2c 0x08,(b8)                ; Read volt from eeprom
readi2c 0x09,(b9)                ; Read volt from eeprom
pause 10
readi2c 0x02,(b10)            ; Read SOC from eeprom
;readi2c 0x03,(b11)            ; Read SOC from eeprom
pause 10
readi2c 0x10,(b12)            ; Read average current from eeprom
readi2c 0x11,(b13)            ; Read average current mins eeprom
debug                        ; Show result

hi2csetup i2cmaster,$78,i2cfast,i2cbyte; 

; Insert your programme code here and then poke 28-91 with message to be displayed
;data to send to display (4 * 16)

poke 28,"C","U","R","R","E","N","T"," "," "," "
bTmp = timetillemptymins / 1000 // 10 + "0" : Poke 38, bTmp
bTmp = timetillemptymins / 100  // 10 + "0" : Poke 39, bTmp
bTmp = timetillemptymins / 10   // 10 + "0" : Poke 40, bTmp
bTmp = timetillemptymins        // 10 + "0" : Poke 41, bTmp
poke 42," "," "
poke 44,"V","o","l","t"," "," "," "," "," "," " ; 
bTmp = Volt / 10000 // 10 + "0" : Poke 54, bTmp
bTmp = Volt / 1000 // 10 + "0" : Poke 55, bTmp
bTmp = Volt / 100  // 10 + "0" : Poke 56, bTmp
bTmp = Volt / 10   // 10 + "0" : Poke 57, bTmp
bTmp = Volt        // 10 + "0" : Poke 58, bTmp
poke 59," "
poke 60,"S","o","c"," "," "," "," "," "," "," "
;bTmp = SOC / 1000 // 10 + "0" : Poke 67, bTmp
;bTmp = SOC / 100  // 10 + "0" : Poke 68, bTmp
bTmp = SOC / 10   // 10 + "0" : Poke 70, bTmp
bTmp = SOC        // 10 + "0" : Poke 71, bTmp
poke 72,"z"," "," "," "," "
poke 76," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "

displaybank = 1 - displaybank         ; toggle lines to display
gosub sendtodisplay             ; load message to display memory and point display at it

; Insert any further code you require here
Pause 30    
serout c.4,N2400,(254,128) ; move to start of first line
serout c.4,N2400,("Time left   ",#w6)
serout c.4,N2400,(254,192) ; move to start of second line
serout c.4,N2400,("Charge      ",#SOC,"%")    




goto main

sendtodisplay:                                                ; sends characters in memory locations 28-91 to the display
for counter = 28 to 91
    PEEK counter, fontlookup                        ; load character to output
    select case fontlookup
        case 48 to 57                            ; 0-9
            fontlookup = fontlookup - 48 * 5
        case 65 to 90                            ; A-Z
            fontlookup = fontlookup -65 * 5 + 50
        case 97 to 122                            ; a-z output as A-Z
            fontlookup = fontlookup - 97 * 5 + 50
        case 123 to 124                            ; a-z output as A-Z
            fontlookup = fontlookup - 97 * 5 + 50
            else
            fontlookup = 244    ; all other characters will display a blank
    endselect                    
    hi2cout 0x40,(0)            ; one blank column
    for subcounter = 0 to 4
        read fontlookup, pixels        
        hi2cout 0x40,(pixels)        ; followed by 5 columns per character
        fontlookup = fontlookup + 1
    next subcounter
    hi2cout 0x40,(0,0)            ; two blank columns
next counter                    ; this completes the 8x8 character output
If displaybank = 0 then
    hi2cout 0x80,(0x40)            ; point display to lines 0-3 of display memory
    else hi2cout 0x80,(0x60)        ; point display to lines 4-7 of display memory
Endif
return
 

hippy

Technical Support
Staff member
any ideas?
No. If it works with a 20M2 then it should work with an 08M2. It might be worth trying a cut-down version of the code on the 20M2 then 08M2 and reporting back on the results -
Code:
#Terminal 4800
main:
i2cslave 0xAA, i2cfast, i2cbyte                
readi2c 0x08,(b8)                ; Read volt from eeprom
readi2c 0x09,(b9)                ; Read volt from eeprom
sertxd( "b8=", #b8, tab, "b9=", #b9, tab, "w4=", #w4, cr, lf )
pause 1000
goto main
I am not sure why the I2C device address is 0xAA when I was under the impression it should be 0x16.
 

tecnition_ted

New Member
Sorry I am altering the address and read area so that it can read different BMS chips. I hope to eventually make a routine that selects different addresses and memory locations from the input of a selector switch, but building up to that need to get everything working first then bugger it up.

This chip is an I2c BQ34z100R1 easy to read and gas gauge only
Bit baffled as just coped the working code straight to an 08M2 everything is working bar the reading of i2c ???

Thank you for all your help I'll try your suggestion and get back shortly.
 

tecnition_ted

New Member
Found the problem! the answer was within another forum. To read i2c and SMB there needs to be two 4.7k pull up resistors on the SCL and SDA pins, for some reason the 20M2 worked without them. I have also added these to the 20M2 and the occasional incorrect read has gone.

Next job sending the serial via Bluetooth to a serial logger then to mobile app

Thank you for the above code Hippy, sometimes you have to take a step backwards and simplify to go forward
 

hippy

Technical Support
Staff member
To read i2c and SMB there needs to be two 4.7k pull up resistors on the SCL and SDA pins, for some reason the 20M2 worked without them. I have also added these to the 20M2 and the occasional incorrect read has gone
Yes, the two pull-ups are essential for I2C and SMBus operation, things will be unreliable without them.

With those fitted it would be worth trying the earlier diagnostics code, modified to reflect what we now know about the actual battery management chip, to see if that now works -
Code:
#Picaxe 20M2
#Terminal 4800
#No_Data

Do
  Pause 3000
  SerTxd( CR, LF )

  HI2cSetup I2CMASTER, 0x16, I2CSLOW, I2CBYTE

  HI2cIn 0x20,(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20)
  SerTxd("Manufacturer=") : Gosub ShowText

  HI2cIn 0x21,(b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14,b15,b16,b17,b18,b19,b20)
  SerTxd("Device=") : Gosub ShowText

  HI2cIn 0x22,(b0,b1,b2,b3,b4)
  SerTxd("Chemistry=") : Gosub ShowText

  ; Day + Month*32 + (Year–1980)*512
  HI2cIn 0x1B,(b0,b1)
  w1 = w0 & 31
  w2 = w0 / 32 & 15
  w3 = w0 / 512 + 1980
  SerTxd("Date=",#w3,"-",#w2,"-",#w1, CR, LF)

Loop

ShowText:
  bPtr = 1
  Do While bPtr <= b0
    If @bPtr >= 0x20 And @bPtr <= 0x7E Then
      SerTxd( @bPtrInc )
    Else
      SerTxd( "<", #@bPtrInc, ">" )
    End If
  Loop
  SerTxd( CR, LF )
  Return
Edit : Changed 0x18 register to 0x1B register for date. See below.
 
Last edited:

tecnition_ted

New Member
Will do and post results. Is it worth starting a new thread regarding attaching this to the serial Bluetooth and WiFi module? There will be questions along the way and I intend to grow the above code so it can read any BQ chip.
 

tecnition_ted

New Member
Here is the reply from the code above all working ok

[reply]

Manufacturer=AceOn
Device=2S14AHPROTOTYPE
Chemistry=LION
Date=2042-8-0

Manufacturer=AceOn
Device=2S14AHPROTOTYPE
Chemistry=LION
Date=2042-8-0

Manufacturer=AceOn
Device=2S14AHPROTOTYPE
Chemistry=LION
Date=2042-8-0

Manufacturer=AceOn
Device=2S14AHPROTOTYPE
Chemistry=LION
Date=2042-8-0
 

hippy

Technical Support
Staff member
Here is the reply from the code above all working ok
Excellent news, though I would guess there's something wrong with my date decoding.

Added : Turns out I was reading the wrong register 0x18 (one-eight ) not the 0x1B (one-bee) it should have been. Change the HI2CIN 0x18,(b0,b1) to HI2CIN 0x1B,(b0,b1) and you should get a more meaningful result.
 
Last edited:

SolidWorksMagi

Senior Member
Hi,

I took me awhile, but once I had basically figured it out I found a way to send data to the OLED display;

3D Printed miniFloppyBot + OLED eyes 2 taming the shrew

Now it's one of the X-Projects on my website: R2Pv1.com
 
Top