Convert C file to FB???

General FreeBASIC programming questions.
Posts: 369
Joined: Dec 04, 2008 15:31

Re: Convert C file to FB???

Postby dasyar » Oct 25, 2014 11:16

The simple program below to get temperature and humidity values from the Sensirion sht11 module attached to the Raspberry Pi GPIO, seems to be working correctly. FreeBasic is a very powerful language!

Somehow this has to be simplified, I used a strict conversion of the existing C code. There were a lot of different steps that had to be dealt with to get to this point. The directory on the RPi holding all these files are very numerous and I hope I can remember all the different steps that occurred in order to produce these files.

If anybody wants to try this out on there own RPi, you will have to follow the posts in this thread and if something is not clear, ask a question. Just thinking, maybe I should try doing a wiringPi version...

Code: Select all

#inclib "bcm2835"
#inclib "RPi_sht1x"
#include ""
#include ""

if bcm2835_init()=-1 then
   print "error: init() fault!"
   sleep : end
end if

dim humi_val as ushort
dim temp_val as ushort
dim realh as single  ' Float
dim realt as single  ' Float
dim realf as single  ' Float

SHT1x_InitPins()  ' Initialise pins, hard coded
SHT1x_Measure_Start(SHT1xMeaT)  ' Temp
SHT1x_Get_Measure_Value(@temp_val) ' Temp
SHT1x_Measure_Start(SHT1xMeaRh)  ' Humidity
SHT1x_Get_Measure_Value(@humi_val)  ' Humidity

realt = CSng(temp_val)  ' Convert integer temp_val to float
realh = CSng(humi_val)  ' Convert integer humi_val to float

'          humidity, temperature
SHt1x_Calc(@realh, @realt)  ' Calculate float values

realf = ((realt*1.8)+30.60)  ' Calculate for F plus adjustment

print "Temp C: " & realt & "C"
print "Temp F: " & realf & "F"
print "Humid: " & realh

print "So far so good!"

Posts: 369
Joined: Dec 04, 2008 15:31

Re: Convert C file to FB???

Postby dasyar » Oct 29, 2014 13:16

Well, I did give it a good try to add sht11 access to the wiringPi lib. The problem that I ran into is that wiringPi does not have a command for reading bytes or bits from a pin. I looked at stealing the code from bcm2835 with the intent of using it in wiringPi, but the C code looked a little to complicated for me to work with, so I will leave that for a more experienced C programmer.

The other thing that I ran into with fbfrog conversion, is that the program does not have the facility to deal with binary code, meaning if you have something like test1 = 0b0001, it comments out the code when it translates it. You will have to go through and look for overlooked code and make the correct adjustment to make it work with your program. Other than that fbfrog is a very good program.

Return to “General”

Who is online

Users browsing this forum: No registered users and 15 guests