Below is rev 2 of the XBsun.bas program, I am now using the bcm2835 lib instead of wiringPi. So far everything is working as expected, I am getting good temperature readings, and the newly attached LEDs are turning on and off. Because of where the LEDs are attached on the GPIO, you have to use the Raspberry Pi B+ model.
As a reminder this is setup to be used with an XBee module plugged in. I was running into some problems with the WiFi module, so I removed that, and now it has a LAN line plugged in, I guess this unit is becoming less mobile.
Now I will be experimenting with the picamera, at first it will be in a stationary position, then I might try mounting it on a movable device.
Code: Select all
'XBsun.bas
' Version 2.0
' Oct 20, 2014
'
' UI program for Raspbery Pi using an XBee on COM port
'
' Oct 21, 2014
' Version 1.0 rev .01
' - Added the dkl auto port search
' - Added time and date commands, displays actual time and date
'
' Oct 29, 2014
' Version 2.0 rev .01
' - Now using the bcm2835 lib
' - Added LEDs to the B+ GPIO on pins 40, 38, 36
#inclib "bcm2835"
#inclib "RPi_sht1x"
#include "bcm2835.bi"
#include "RPi_SHT1x.bi"
'#include once "wirringpi.bi" ' Not using wiringPi
#include "vbcompat.bi" ' Date function
' Define the GPIO pins
#define rPIN RPI_BPLUS_GPIO_J8_40
#define gPIN RPI_BPLUS_GPIO_J8_38
#define yPIN RPI_BPLUS_GPIO_J8_36
' Check to see if bcm2835 is setup
if bcm2835_init()=-1 then
print "error: init() fault!"
sleep : end
end if
' Init pins for
bcm2835_gpio_fsel(rPIN, BCM2835_GPIO_FSEL_OUTP)
bcm2835_gpio_fsel(gPIN, BCM2835_GPIO_FSEL_OUTP)
bcm2835_gpio_fsel(yPIN, BCM2835_GPIO_FSEL_OUTP)
' Check to see if wiringPi is setup
'if wiringPiSetup()=-1 then
' print "error: Can't setup GPIO!"
' sleep : end
'end if
' Declare Subs
declare sub ronled()
declare sub roffled()
declare sub gonled()
declare sub goffled()
declare sub yonled()
declare sub yoffled()
declare sub tempmod()
declare sub menu()
' Declare functions
' Declare global variables
dim as string Key,buffer,buffer1
' Check for open com port.
dim portsToTry(0 to ...) as string => _
{ _
"/dev/ttyUSB0", _
"/dev/ttyUSB1", _
"/dev/ttyUSB2", _
"/dev/ttyUSB3" _
}
var settings = ":9600,n,8,1,cs0,ds0,cd0,rs" ' Settings for port
dim f as integer
for i as integer = 0 to ubound(portsToTry)
var port = portsToTry(i)
print "trying '" + port + "'... ";
f = freefile()
if open com(port + settings, as #1) = 0 then
print "ok"
exit for
end if
print "failed"
f = -1
next
if f < 0 then
print "Could not find any working ports!"
end 1
goto Cend ' Added this just in case
end if
'**********
' Main
startp:
print "Started program."
print #1, " XBsun"
do
' Check locally for Esc key press
Key = inkey$
if Key = chr$(27) then
exit do
end if
' Check for incoming on com port
while Loc(1) > 0
buffer = input$(loc(1),#1)
buffer1 = buffer1 + buffer
if buffer = chr$(27) then ' Check for Esc key press, remote
goto Cend
end if
if buffer = chr$(13) then
print buffer1 ' Log a session to a file at this point ?
buffer1 = rtrim(buffer1, chr$(13)) ' End of str CR trim
if buffer1 = "quit" then ' Check for 'quit' command
goto Cend
elseif buffer1 = "ronled" then ' Check for 'ronled' command
ronled()
elseif buffer1 = "roffled" then ' Check for 'roffled' command
roffled()
elseif buffer1 = "gonled" then ' Check for 'gonled' command
gonled()
elseif buffer1 = "goffled" then ' Check for 'goffled' command
goffled()
elseif buffer1 = "yonled" then ' Check for 'yonled' command
yonled()
elseif buffer1 = "yoffled" then ' Check for 'yoffled' command
yoffled()
elseif buffer1 = "help" or buffer1 = "?" then
menu()
elseif buffer1 = "date" then
print #1, Date
elseif buffer1 = "time" then
print #1, Time
elseif buffer1 = "temp" then
tempmod()
else
print #1, "Unknown Command"
end if
buffer1 = ""
end if
wend
''''''''''''''''''''
sleep 1,0
loop
'**********
Cend:
print #1, "Program stop"
close ' Close open com port
end
' Functions and subRoutines
' Turn on rLED on pin GPIO21
sub ronled()
' pinMode(6, PIN_OUTPUT) ' Not using wiringPi
' digitalWrite(6,PIN_HIGH) ' Not using wiringPi
bcm2835_gpio_write(rPIN,HIGH)
end sub
' Turn off LED on pin GPIO21
sub roffled()
' pinMode(6, PIN_OUTPUT) ' Not using wiringPi
' digitalWrite(6,PIN_LOW) ' Not using wiringPi
bcm2835_gpio_write(rPIN,LOW)
end sub
sub gonled()
bcm2835_gpio_write(gPIN,HIGH)
end sub
sub goffled()
bcm2835_gpio_write(gPIN,LOW)
end sub
sub yonled()
bcm2835_gpio_write(yPIN,HIGH)
end sub
sub yoffled()
bcm2835_gpio_write(yPIN,LOW)
end sub
sub tempmod()
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_Reset()
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 #1, "Temp C: " & realt & "C"
print #1, "Temp F: " & realf & "F"
print #1, "Humid: " & realh
end sub
sub menu()
print #1, "Menu - help, quit, time, temp, date "
print #1, " ronled, roffled, "
print #1, "quit stops the program"
end sub