BASIC User Group > NOT BASIC

RPI Sense HAT and 8th

<< < (2/2)

jalih:

--- Quote from: John on April 27, 2019, 11:38:26 am ---Nope.

--- End quote ---

I accidentally packaged the original erronous script and posted it to dropbox, not the corrected one. I could see it from the error message thrown. Corrected version doesn't have dot at the end of the message.

Now the dropbox link above should work poperly and have the corrected binary.

John:
Success!


pi@RPi3B:~/rpi8th/rpi32_3 $ ./test
42.50000
pi@RPi3B:~/rpi8th/rpi32_3 $ scriba ~/sbrpi/examples/testhat.sb
Pressure: 756
P-Temp: 425
Humidity: 390
H-Temp: 255
Accel-x: 0
Accel-y: 0
Accel-z: 0
Mag-x: -1982
Mag-y: 1416
Mag-z: -386
Gyro-x: 1591
Gyro-y: 877
Gyro-z: 75
pi@RPi3B:~/rpi8th/rpi32_3 $


jalih:

--- Quote from: John on April 27, 2019, 12:21:57 pm ---Success!

--- End quote ---

Thanks,

Seems like I messed up with "wait-results" word also! :D I did'nt wait correctly for measurement to be complete. I corrected my code and uploaded new binary to the dropbox. Good thing is that communicating with Sense HAT works properly from 8th! Thanks John for testing my code.

After I get my ROCK64 board, I will try attaching some sensors and interfacing them...


--- Code: ---
: DEV_ID    0x5c ;
: WHO_AM_I  0x0f ;

: CTRL_REG1 0x20 ;
: CTRL_REG2 0x21 ;

: TEMP_OUT_L   0x2b ;
: TEMP_OUT_H   0x2c ;


var LPS25H


: init
  1 DEV_ID hw:i2c null? if
    drop
    DEV_ID "Cannot connect to the LPS25H on I2C address %02x" s:strfmt throw
  else
    WHO_AM_I true hw:i2c@reg null? not if
      0xbd n:= not if
        "who_am_i error" throw
      then
    else
      WHO_AM_I "error reading from %02x" s:strfmt throw
    then
  then

  LPS25H ! ;


: power-down
  LPS25H @ CTRL_REG1 0x00 true hw:i2c!reg nip not if
   "Error powering down the device" throw
  then ;


: set-mode
  LPS25H @ CTRL_REG1 0x84 true hw:i2c!reg nip not if
   "Error turning on the pressure sensor analog front end in single shot mode" throw
  then ;


: one-shot-measure
  LPS25H @ CTRL_REG2 0x01 true hw:i2c!reg nip not if
   "Error running one-shot measurement (temperature and pressure)" throw
  then ;


: wait-results
  repeat
    0.025 sleep
    LPS25H @ CTRL_REG2 true hw:i2c@reg nip null? if
      drop
      "Error reading measurement status" throw
    then
    0 n:= if
      break
    then
  again ;


: get-temp  \  -- temp
  LPS25H @ TEMP_OUT_L true hw:i2c@reg nip null? if
    drop
    "Error reading low byte of the temperature" throw
  then

  LPS25H @ TEMP_OUT_H true hw:i2c@reg nip null? if
    drop
    "Error reading high byte of the temperature" throw
  then

  8 n:shl n:bor 480 n:/ 42.5 n:+ ;


: app:main
  init
  power-down
  set-mode
  one-shot-measure
  wait-results
  get-temp . cr
  power-down
  bye ;

--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version