Great, thanks for the fix! That should make things easier for me moving forward. For now I thought I'd share some test code I've thrown together. This is basic proof of concept that I can get python to talk to the Bus Pirate. I'm using a Dallas DS1820 1-wire temp sensor.
import serial
ser = serial.Serial('/dev/ttyUSB0', 115200, timeout=0.05)
print ser.read(100)
#Funtion sends one byte at a time to the BP
def writeBytes(myData):
for c in myData:
ser.write(c)
s = ser.read(100)
for c in s:
print '%02X'%ord(c),
print
return s
#Put BP into Bit Bang mode (Mode LED should light up)
ser.write("x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00x00")
s = ser.read(100)
print s
#Put BP into 1-wire mode
writeBytes("x04")
#Turn on voltage regulator
writeBytes("x48")
#bus reset
writeBytes("x02")
#Get address
s = writeBytes("x08")
#Slice out 8 bytes excluding the first byte (it was a confirmation byte)
tempSensorAddr = s[1:9]
print "nUsing 1-Wire Address:"
for c in tempSensorAddr:
print '%02X'%ord(c),
print "n"
#bus reset
writeBytes("x02")
#Start conversion by sending 0x44
writeBytes("x19x55" + tempSensorAddr + "x44")
#bus reset
writeBytes("x02")
#Read from sketchpad by sending 0xBE
writeBytes("x19x55" + tempSensorAddr + "xBE")
#Read first two bytes
lsByte = writeBytes("x04")
msByte = writeBytes("x04")
#Convert lsByte and msByte to a usable decimal sum
lsByte = int(ord(lsByte))
msByte = int(ord(msByte))*256
rawTemp = lsByte + msByte
print rawTemp
#Convert rawTemp to precision temp, then to Fahrenheit
tempCelsius = rawTemp * 0.0625
print "Temperature Celsius: ", tempCelsius
tempFahrenheit = ((tempCelsius*9)/5)+32
print "Temperature Fahrenheit: ", tempFahrenheit
Here's the output of the script:
BBIO1
Bus Pirate v3
Firmware v4.2 (rxxx) Bootloader v4.1
DEVID:0x0447 REVID:0x3003 (A3)
http://
dangerousprototypes.com
HiZ>BBIO1
31 57 30 31
01
01
01 28 A8 CD 5E 02 00 00 AF FF FF FF FF FF FF FF FF
Using 1-Wire Address:
28 A8 CD 5E 02 00 00 AF
01
01 01 01 01 01 01 01 01 01 01 01
01
01 01 01 01 01 01 01 01 01 01 01
75
01
373
Temperature Celsius: 23.3125
Temperature Fahrenheit: 73.9625