Multi-digit word variable to string


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 44
  1. #1
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198

    Default Multi-digit word variable to string

    Good morning.

    I have recently resurrected an old project as a means of introducing myself to PBP3 and the PIC16F88. It is a scrolling marquee on a single 5x7 matrix LED; the characters are 5x5 and with some missteps, I am now able to display a static message quite satisfactorily. Yaye me!

    To extend my knowledge, I determined to interface an LM34 temperature sensor as demonstrated here: http://www.rentron.com/PicBasic/LM34.htm. The project calls for a PIC16F677--the ADC setup is different, but therein lays the learning. Armed with the datasheet, I went to work… a reasonable period later, I felt I had adequate understanding to program some code.

    While I may (or may not) have gotten the ADC configured properly, the real frustration is displaying the result! I had intended to use the [DEC] statement, [DIG], and some division to insert each digit into the string array for display, but [DEC RawT (the word variable holding the ADC result)] results in a “Bad expression” error. I had thought perhaps that my ADC result was indecipherable, but even setting RawT to a likely value does not change the result.

    TL;DR:
    Can someone with a better understanding demonstrate how a multi-digit word variable be converted to a single digit string format; i.e. RawT=754 --> MSG[x]= “7”, MSG[x+1]= “5”, MSG[x+2]= “4”? Also, seeing that I’ve impinged on your good nature already, can you verify my ADC configuration to read from AN0 on pin17, using a +Vref on AN3 (pin 2)?

    Many thanks...

    CONFIG:
    #CONFIG
    __config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF
    __config _CONFIG2, _FCMEN_OFF & _IESO_OFF
    #ENDCONFIG

    DEFINE OSC 8
    OSCCON = %01110000
    ANSEL = %00001001 'ANALOG OFF, EXCEPT +Vref AND AN3
    TRISA = %0001001 'PORTS TO MATCH ANSEL
    ADCON1.7 = 0 : ADCON1.6 = 0 : ADCON1.5 = 1 : ADCON1.4 = 0 'LEFT JUSTIFIED : ADCS2 DISABLED : VCFG Vref+ AVSS
    ADCON0 = %01011001 'Fosc/8 : AN3 ACTIVE : ADON (BIT0) ADC ON
    TRISB=0 'PORTB DIGITAL



  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hi,
    One way could be to use the ArrayWrite command, something like:
    Code:
    MSG VAR BYTE[4]
    RawT VAR BYTE
    
    RawT = 754
    
    ARRAYWRITE MSG, [DEC RawT]
    /Henrik.

  3. #3
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Thank you, Henrik.
    I love when the answer is shorter than the question!

    To be clear then, it appears that DEC is not a command of itself, but a parameter of some other display functions; it is only valid in an output string to an LCD or other output device (ie serial port) or construct (array-obviously).

    I hope it is not too much trouble for any who follow this thread to correct my interpretation as well as to clarify one more point? Can an entry point be specified, as ARRAYWRITE MSG[14], [DEC RawT] so that the variable may be positioned in a larger array? I saw little on this when searching

    It is possible to specify an entrypoint, so that (for example) the string "Temperature = XXX degrees" can be dynamically updated with Arraywrite ARRAYNAME[entrypoint] = [DEC variable]
    Last edited by Amoque; - 25th March 2012 at 20:44.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hi,
    That's correct. DEC is not a command by itself, it's what the manual calls a modifier among others (BIN, HEX etc).

    I've never tried it but I'm pretty sure you can start anywhere in the array in the way you show.

    /Henrik.

  5. #5
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hello all,

    this is an old post. I'm not sure if my question fits right to here.

    I have a temperature values and i would like to send them to a display from 4D Systems.

    At the moment i was using the serial SPE commands as 4D Systems calls it, and they have exactly the command to send those variables.

    Then i tried their "new" Visi Genie enviroment, which allows you to create "forms" and add any image, button etc.

    I have fniished the easy task inside the Visi Genie and i'm in front of a problem that i need to transform the variable to string.

    As from 4D Systems:

    Visie-Genie writes to pre-defined objects so in this case it is a pre-defined string object so all we have to do is convert what we need to send to a string, calculate a checksum and send. This is where Genie differs from Serial as in the Serial mode you are sending a serial command to the display which is translated to a command to do a supported function on the display.
    It is the first time i had to do a task with Checksum and found it interesting way by XORing all the bytes. In a very small code i tryied it worked, as i sent based on 4D Systems the command to change the constrast and it worked.

    Code:
    command var byte
    constrast var byte
    CS var byte
    
    ' -----------------------------------------------------------------------------|
    ' [ LCD Initialization ] |
    '------------------------------------------------------------------------------|
    ' FIRST TIME BOOTUP: We give plenty of time for tbe LCD '
    lcdinit:
    pause 2000
    command = $04
    contrast = $06
    gosub checksum
    hserout [command,contrast,CS]
    hserin [wait(6)]
    pause 100
    
    
    high green
    return
    
    '------------------------------------------------------------------------------|
    ' CHECKSUM |
    '------------------------------------------------------------------------------|
    checksum:
    cs = 0
    cs = cs ^command
    cs = cs ^ contrast
    return
    Now i'm trying to see the way to convert var to string. I have read the manual written in 2013

    "A numeric value preceded by a pound sign ( # ) will send the ASCII representation of its decimal value, up to 65535. For example, if W0 = 123, then #W0 (or #123) will send "1", "2", "3"."
    Is that the right way? May i have your help please?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Or use DEC modifier like DEC k. If k=5, DEC k will send out the "5".

    With DEC you can also specify how many digits you will send. E.g. DEC3 will send 3 digit of the variable with the appropriate leading zeros in this case to fit the number of digits requested.

    If k=15 then DEC3 k will send "0", "1", "5"

    Ioannis
    Last edited by Ioannis; - 28th September 2020 at 10:57.

  7. #7
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Thanks so much Ioanni,

    will try it out.

  8. #8
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Dear all,

    i have some problem regarding the conversion of a variable to string.

    I have the following code.


    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                         VAR for IR to LCD          '
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    IRCS         var byte       ' this is the checksum for the IR required in external display command
    TEMP         var word       ' this is the word variable for TEMP 
    temperature  var word       ' for result and output to lcd 
    TEMPIR       var word       ' set a variable tempir 
    Remainder    var word       ' Get the remainder = tempir//50
    
    '------------------------------------------------------------------------------*
    '                    Measure IR object temp sent to uLCD                          *
    '------------------------------------------------------------------------------*
    object:
    
    reg    = $07             ' based on the datasheet $07 is the object's temp
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    addr   = %10110101       ' $B5  Binary value: %10110101
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07
    
    
    tempir = (temp.highbyte << 8) + temp.lowbyte
    
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    pause 100
    gosub display
    return
    
    '------------------------------------------------------------------------------*
    '                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature,".",dec2 remainder,"*C",00] 'this one works on display 1 which doesnt require CS 
    Hserin2  timeout,error,[wait(6)]
     
    
    gosub checksum2    
    hserout [$01,$0F,$00,temperature,remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature
    IRCS = IRCS ^ remainder
    return

    One i do the CS calculation, and returning from checksum2 the following is not working as expectred.

    Code:
    hserout [$01,$0F,$00,temperature,remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    even if i try the following.

    Code:
    hserout [$01,$0F,$00,dec2 temperature,dec remainder,IRCS]   ' this one doent work, i get random numbers on the display. 
    Hserin  timeout,error,[wait(6)]
    return
    Is there a way to convert the variable to string ourside from a preset command like the HSEROUT?

    for example is there a way to make something like this in PBP?

    temperature = #temperature.

  9. #9
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If your variable is ranging from 0 to 65536 (the maximum that word can hold) obviously the HSEROUT command cannot handle that. With HSEROUT you can use only ascii values.

    So, as you have already find out, the dec2 temperature does work. Maybe your value is beyond 2 decimals so you have to use dec5 to be sure and cover all temperature values?

    Ioannis

  10. #10
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Ioanni,

    i do write the following for me to understand.

    i have the var TEMPIR which gives a value for example of 14450.

    Then i do have an other VAR which is temperature.

    If i devide
    Code:
    temperature = TEMPIR / 50
    we get
    Code:
    289
    .

    then for getting the temp value we do
    Code:
    temperature = temperature - 273
    , which gives to us 16. But we do not get the remainder value.

    The remainder value is
    Code:
    Remainder = TEMPIR*2//100
    , which the result is 9 for our example of 14450.

    Now i have an LCD that requires a CS value to be added in a command.

    Name:  command.png
Views: 829
Size:  15.3 KB

    Thats why i gosub to find and calculate the CS value of the overal command.

    I think that i need somehow to calculate and convert the variable to string, ourside from the HSEROUT command.

    Apparently the DEC5 didnt work.

  11. #11
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    The msb and lsb in your display string what are exactly? Ascii values or binary?

    And being msb and lsb, I understand that these two construct a word value. For what purpose? Your display for example, can display on screen a binary word value of %0000000000000001 as plain 1?

    Ioannis

  12. #12
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    According to the manual of the display and the VISI GENIE OS.

    The following is an example.

    Name:  command2.png
Views: 799
Size:  81.8 KB

    I'm missing something, because right now as the code is, returning from the Checksum calculation, the HSEROUT command is set right. But i do get HEX result. Right?

  13. #13
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    The number is just the same either hex, binary or decimal. 128 is the same as %10000000 or $80. You show it in different way.

    The trackbar object, what exactly is?

    Ioannis

  14. #14
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Trackbar is only an object ID in VISI GENIE OS for the Display like the following.

    Name:  command3.png
Views: 695
Size:  54.5 KB

    in our case we do use the LEDDIGITS which the OBJECT ID is $0F

    Name:  command4.png
Views: 707
Size:  37.8 KB

  15. #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    OK, I see.

    So, if you want to move the trackbar to position $28 you will use

    Code:
    HserOut [$01,$05,$00,$00,$28,$2C]
    and the slider will goto position $28.

    But I guess you have to set beforehand the two ends of the trackbar? I mean the zero can be 100 and the maximum position 200, or whatever.

    Can you try and see if you can move the trackbar just by sending straight in values? and the CRC computed by hand.

    Then you may do more complicated things.

    Ioannis

  16. #16
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    in my case i do not use the trackbar, but the LED digits as shown below.

    Name:  command5.png
Views: 717
Size:  90.0 KB

    In the software 4D SYstems they have, you can set manually a number for example 167, and will show you the command as shown in the SET DIGIT VALUE:

    Name:  command6.png
Views: 704
Size:  36.4 KB

    I have tried to give manually a constant number and it worked!

    what i did is:

    i set a new var mTEMP ' for manually hex number and
    a new var mTEMPIR ' for manually hex number as well.

    In our case the number 167 for:

    Code:
    mTEMP = $00
    mTEMPIR = $a7
    then i did the CS calculation and return to the HSEROUT command.

    Code:
    IRCS=0
    IRCS= $01^$0F^$00^mTEMP
    IRCS = IRCS ^ mTEMPIR
    I placed it with:

    Code:
    HSEROUT [$01,$0F,$00,mTEMP,mTEMPIR,IRCS)
    then i got the right result on the display.

    The problem is that when i use the variables i cannot get the right values.
    Last edited by astanapane; - 18th December 2021 at 23:14.

  17. #17
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    i assume the real question in this jumble is how do i sent a word var as a binary number msb first using hserout

    Temp var word
    Temp=167


    HSEROUT [$01,$0F,$00,Temp.highbyte,Temp.lowbyte,IRCS)
    Warning I'm not a teacher

  18. #18
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard!!!!

    it really worked!!!

    Code:
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    '                         VAR for IR to LCD          '
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    IRCS         var byte       ' this is the checksum for the IR required in external display command
    TEMP         var word       ' this is the word variable for TEMP 
    temperature  var word       ' for result and output to lcd 
    TEMPIR       var word       ' set a variable tempir 
    Remainder    var word       ' Get the remainder = tempir//50
    
    '------------------------------------------------------------------------------*
    '                    Measure IR object temp sent to uLCD                          *
    '------------------------------------------------------------------------------*
    object:
    
    reg    = $07             ' based on the datasheet $07 is the object's temp
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    addr   = %10110101       ' $B5  Binary value: %10110101
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07
    
    tempir = (temp.highbyte << 8) + temp.lowbyte
    
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    pause 100
    gosub display
    return
    
    '------------------------------------------------------------------------------*
    '                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature,".",dec2 remainder,"*C",00] 'this one works on display 1 which doesnt require CS 
    Hserin2  timeout,error,[wait(6)]
     
    
    gosub checksum2    
    HSEROUT [$01,$0F,$00,temperature.highbyte,temperature.lowbyte,IRCS)   ' this one works.
    Hserin  timeout,error,[wait(6)]
    return
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature
    'IRCS = IRCS ^ remainder ' commended this as i need to figure out how to import it in the HSEROUT command.
    return
    Now i'm trying to figure out how to add the remainder in the command.

  19. #19
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Now i'm trying to figure out how to add the remainder in the command.
    i hope this is not a medical diagnostic device
    your temperature calculation is not accurate and the remainder calculation is mathematically incorrect


    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    yields the temp in deg C to about 1 deg of resolution with an error of +- 1 degree

    Code:
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    calculated the 100 modulus of the temp in deg kelvin

    adding them together is nonsense , trying to display a two decimal point result is from any of these results is just not right

    Name:  Screenshot 2021-12-19 163013.jpg
Views: 735
Size:  194.2 KB

    Code:
    wtf tempir = (temp.highbyte << 8) + temp.lowbyte ;just Nooooo! its the hardest most convoluted way i have ever encountered to go 
    tempir = temp which serves no purpose anyway
    
    
    
    
    don't like this either, it pisses away too much resolution hence its not particularly accurate 
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    remainder    = (tempir*2)//100   ' multiply x 2 and get the remainder //100
    
    
    ;this is good  although it could be even more accurate [temperature  = temp*2  - 27315 ; temp x 2 - 273.15*100 ] >==>temperature*100] if the raw value won't exceed 32768 
    
    
    temperature  = (temp  - 13657)<<1  ; (temp-[273.15*50]) x 2   <==> temperature*100; is good
    
    
    
    
    i make the assumption temperature * 100 is the value required by the slider display
    
    
    tempir and remainder are not needed
    display like this

    Code:
    '------------------------------------------------------------------------------*'                    IR  Display 1 the parameters                              *
    '------------------------------------------------------------------------------*
    display: ' IR TEMP 
    hserout2 [$73,$00,$02,$12,$00,$ff,"IR TEMP:",00]
    Hserin2  timeout,error,[wait(6)]
    hserout2 [$73,$08,$02,$12,$F8,$00,dec2 temperature/100,".",dec2 temperature//100,"*C",00] 
    Hserin2  timeout,error,[wait(6)]
     
    
    
    gosub checksum2    
    hserout [$01,$0F,$00,temperature.highbyte,temperature.lowbyte,IRCS]   
    Hserin  timeout,error,[wait(6)]
    return
    
    
    '------------------------------------------------------------------------------|
    '                               CHECKSUM IR                                    |
    '------------------------------------------------------------------------------|
    checksum2:
    IRCS = 0
    IRCS = $01 ^ $0F ^ $00 ^ temperature.highbyte ^ temperature.lowbyte 
    return

    then lets have a look at the i2c stuff , its not right either really


    ps if negative temps are possible then additional code req
    Last edited by richard; - 19th December 2021 at 10:07.
    Warning I'm not a teacher

  20. #20
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    really thanks for your time.

    I found this,if i remember correctly somewhere related to this specific sensor.

    Code:
    tempir = (temp.highbyte << 8) + temp.lowbyte
    Then in the equation i have added the following
    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    Your way is much more efficient and works just as expected. Im very happy.

    Now what is wrong with the I2C command?
    Attached Images Attached Images  

  21. #21
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string


    I found this,if i remember correctly somewhere related to this specific sensor.


    Code:
    tempir = (temp.highbyte << 8) + temp.lowbyte
    maybe but in conjunction with
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07

    its not useful in any way

    Now what is wrong with the I2C command?
    all this achieves is exactly nothing
    Code:
    reg    = $07             ' based on the datasheet $07 is the object's temp
    
    
    grave doubts about all of this  it looks like some mishmash of a C code method where no read/write register command exists as it does in pbp 
    addr   = %10110100       ' $B4  binary value: %10110100
    i2cwrite SDA, scl, addr  ' send write command, shift the address B4, 8 bits where LSB is W = 0
    i2cwrite sda, scl, reg   ' register is $07
    
    
    i2cwrite sda, scl, addr,reg, [some data of some sort]  ' register is $07 ;would be the normal way if you had any data to write 
    
    
    totally bogus in pbp bit 0 should always be 0
    addr   = %10110101       ' $B5  Binary value: %10110101
    
    
    a form of torture to i2c chips with an incomplete transaction
    i2cwrite sda, scl, addr  ' sends read command, shift the address B5, 8 bits where LSB is R = 1, clock idles low
    all that's needed
    reg = $07
    addr = %10110100
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07 ;would be the normal pbp way
    Warning I'm not a teacher

  22. #22
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Quote Originally Posted by astanapane View Post
    Richard,

    Then in the equation i have added the following
    Code:
    temperature  = tempir/50         ' based on the manual we need to divide by 50 or 0.02
    temperature  = temperature - 273 ' subtract 273 for Degree in C,actually is 273,15
    Well, if that compiler could do floating, maybe it could be used. But in PBP integer math? I do not think so. You need what Richard did as a workaround.

    Ioannis

  23. #23
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    now i got a bit comfused. If i only add the following, it doent work as expected

    all that's needed
    reg = $07
    addr = %10110100
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte] ' reg = $07 ;would be the normal pbp way
    But if i add the write mode and I2Cwrite command it works.
    Code:
    reg = $07 ' this is the register for IR temp mode
    addr= %10110100 ; this is the write mode
    
    i2cwrite SDA, SCL, addr 
    i2cread SDA, SCL, addr, reg, [TEMP.lowbyte, TEMP.highbyte]
    the following also works.

    Code:
    reg = $07 ' this is the register for IR temp mode
    addr= %10110100 ; this is the write mode
    i2cwrite SDA, SCL, addr 
    
    addr= %10110101 ; this is the read mode
    i2cread SDA, SCL, addr, reg, [TEMP.lowbyte, TEMP.highbyte]
    if i do not add the following line the code doesnt work.

    Code:
    i2cwrite SDA, SCL, addr
    Shouldnt we write first and then read? ok i understand that we have nothing to write. But why it doent work if i do not add the i2cwrite line?

  24. #24
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Shouldnt we write first and then read? ok i understand that we have nothing to write. But why it doent work if i do not add the i2cwrite line?
    which is precisely what the i2cread command does for you automatically. it should not ever be necessary to add a extra write , no i2c chip i have ever encountered has needed such treatment


    i2cwrite SDA, SCL, addr
    is an incomplete transaction. if your chip needs it then it is not a true i2c device or something else is occurring.
    a logic analyzer would show what's really happening. its not normal and should be examined further to have any confidence
    that the code is really viable in the long term

    addr = %10110100
    trying to set bit0 [the r/w bit] of a i2c address with pbp's i2c commands is not possible and will not have any effect
    the code will set the r/w bit as needed
    Warning I'm not a teacher

  25. #25
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    it could be the chip is not really i2c and behaves differently

    try this, at least its a nicer transaction
    i2cwrite SDA, SCL, addr,[7]
    i2cread SDA, SCL, addr,[TEMP.lowbyte, TEMP.highbyte]



    looking at the wiki link you posted, this would do exactly what the smbus timing diagram describes as a proceedure

    PEC var byte
    i2cread SDA, SCL,addr,reg,[temp.lowbyte,temp.highbyte,PEC] ' reg = $07 ;would be the normal pbp way

    worth trying
    Last edited by richard; - 19th December 2021 at 14:13. Reason: wiki
    Warning I'm not a teacher

  26. #26
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Hi Richard,

    sure i'll try that, and i will try to figure out what is going on with a logic analyzer.

    I have a saleae logic 8.

    Will try that later today. Many thanks for your time once again.

  27. #27
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If there is only one MLX90614 sensor, the 7-bits address is 0x00 by default.
    according to wiki addr =0 where did you get B4 from ?

  28. #28
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    If the chip is the MAX30102, on page 16 seems that reading needs first a write.

    Ioannis

  29. #29
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    wait a sec,

    im reading the manual again from the SENSOR

    https://www.waveshare.com/w/upload/e/e4/MLX90614-EN.pdf

    Name:  ir sensor 2.png
Views: 661
Size:  92.8 KB
    Last edited by astanapane; - 19th December 2021 at 14:54.

  30. #30
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Quote Originally Posted by Ioannis View Post
    If the chip is the MAX30102, on page 16 seems that reading needs first a write.

    Ioannis
    it is an IR MLX90614

  31. #31
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Applying the 0x00 is not working.

    When i add back the B4 or B5 for write or read mode correspondingly, everything is in a working order again.

  32. #32
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Its hard to work with crappy information


    Name:  LEO.jpg
Views: 658
Size:  86.1 KB

    i2cread SDA, SCL,$b4,7,[temp.lowbyte,temp.highbyte,PEC] will do exactly that


    i just realized that what code you posted is in fact a snippet .
    addr and reg are never defined , osc is unknown ,i2c defines unknown, pin settings and i2c pull ups ...........

    could be another waste of time
    Warning I'm not a teacher

  33. #33
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    i have thanked you so many times for your effort and help.

    I think i have attached in the code most of the information required.

    You have helped me in the first major issue i had with the right values and the command needed inside the HSEROUT.

    Then we moved to I2C command. I think there i have shared the reg and addr values. For the SCL and SDA i dont think that is necessary at all to post which port is or not.

    Anyway, now the code is working just fine and i need once again to thank you all for your help and time.

    Once again Richard. Life is simpler and shorter than we all think. Smile because you have the knowledge in this field to help people.

  34. #34
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    out of curiosity i downloaded the real data sheet and discovered quite a few things
    Name:  lb.jpg
Views: 656
Size:  141.1 KB

    1 the bus speed is 100khz
    2 the datasheet depicts an abnormally long repeated start signal on a read transaction [no specs but]
    3 the bus needs a SMBus Request signal before a read/write transaction
    4 the genuine article has addr 0 not 0xb4

    looking at ebay banggood aliexpress etc yields a 5 to 1 price range from $10 to nearly $60 us
    most venders spruking a multitude of part numbers in the listing, you would wonder what you are buying
    i suspect clones fakes and lookalikes abound

    a real one from e14 or rs is $40ish au , a bit much for a play trinket for me
    so i don't think i can take it much further
    Warning I'm not a teacher

  35. #35
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    I think i have attached in the code most of the information required.

    Then we moved to I2C command. I think there i have shared the reg and addr values. For the SCL and SDA i dont think that is necessary at all to post which port is or not.
    wrong on all counts

    the i2c defines and osc speed can be crucial to i2c bus problems
    pin and port settings can also play a vital role
    the type of vars defined for reg and addr are also important ,for instance if reg is a word var then all bets are off

    sorry i tried
    Warning I'm not a teacher

  36. #36
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Richard,

    your help is always appreciated. You were right once again.

    I had the

    Code:
    reg var Word
    I think i've seen it as a comment somewhere here in the forum.

    Now i have changed the code and used byte insted of word for the reg and used only the code line you suggested and taaaadaaa, it worked.

    Apart from that......

    i think i have the original from melexis the IR module as it cost here in Europe around 25 Euros.

    The link of the Datasheet is the following.

    https://www.melexis.com/en/documents...sheet-mlx90614

    and this is the part of the datasheet shown the revision and the date.

    Name:  melexis.png
Views: 652
Size:  136.8 KB
    Last edited by astanapane; - 20th December 2021 at 11:25.

  37. #37
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    Quote Originally Posted by richard View Post
    Its hard to work with crappy information
    could be another waste of time
    and it was

    I had the
    reg var Word
    I think i've seen it as a comment somewhere here in the forum.
    a classic case of monkey see monkey do programming error hidden away by use of snippets
    days wasted, hundreds of posts to solve an elementary error.

    i would not be surprised to find there is still one more major issue for the i2c settings still not addressed
    for this precious secret code . i hope this is not a medical diagnostic device

  38. #38
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    ------------------------

    is there a point to answer to such a negative behavior and bad attitute? I think you have a problem man. Get a girl.
    Last edited by astanapane; - 20th December 2021 at 23:03.

  39. #39
    Join Date
    May 2013
    Location
    australia
    Posts
    2,383


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    is there a point to answer to such a negative behavior and bad attitute
    i don't mind your attitude so much, its just a wonder to me that anyone could come to this forum looking for free programming help.
    help for a problem they cannot solve themselves , then refuse or begrudgingly supply the detail identified as potentially problematic.
    you expect solutions from code snippets that only bring a problem to light not actually cause it.
    solutions are offered , pitfalls exposed even though the necessary info had to be painstakingly extracted over numerous posts.
    then only to be met with anger and indignation , you have to laugh

    but there is a point. snippets have been shown to be a waste of time over and over again
    Warning I'm not a teacher

  40. #40
    Join Date
    Oct 2010
    Posts
    411


    Did you find this post helpful? Yes | No

    Default Re: Multi-digit word variable to string

    fix your inside first.

    You share a proof data document to me from 2009, and you are trying to tell me that i have a fake module.

    You still do not listen. Forget about me and my monkey programming. Forget everything! You may be a good programmer, but a very very bad teacher or someone that could help in a forum.

    Check the answers from DT in the past. Check and learn from his kidness and for his possitive behaviour. LEARN man LEARN.

    YOU NEED HELP MAN anyway.....from medical side. I cannot help you from here, but still, listen to me at least and ask for a help soon.

    Hope you will find your way. You need help.

    I will be here if you need to talk to someone, but medically i cannot help you.

    Thanks once again for all the help and time you spent.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts