clvlabs / buspirate Goto Github PK
View Code? Open in Web Editor NEWA simple scripting tool for Bus Pirate written in Python.
A simple scripting tool for Bus Pirate written in Python.
Voltmetr mode of ADC produced never ending series of values. It doesn't work. Well, BusPirate is switched to voltmeter mode but this Python script doesn't read values. Voltage values are not separated by new line but rewritten in place with "0x08" control codes.
Example, test.txt:
d
d
D
Serial console, BusPirate:
HiZ>#
RE
Bus Pirate v3.b clone w/different PIC
Firmware v6.1 r1676 Bootloader v4.4
DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
http://dangerousprototypes.com
HiZ>d
VOLTAGE PROBE: 0.00V
HiZ>d
VOLTAGE PROBE: 0.00V
HiZ>D
VOLTMETER MODE
Any key to exit
VOLTAGE PROBE: 0.00V
HiZ>
Script run with Python
***[ Bus Pirate scripting tool ]********************************************************************
Script file test.txt
COM port /dev/ttyUSB2
- Opening serial port
[OK] Serial port open
- Resetting board
>>> ------------------------------------| #
<<< #
<<< RE
<<< Bus Pirate v3.b clone w/different PIC
<<< Firmware v6.1 r1676 Bootloader v4.4
<<< DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
<<< http://dangerousprototypes.com
<<< HiZ>
- Sending script file (test.txt) - 4 lines
- Resetting board
>>> ------------------------------------| #
<<< #
<<< RE
<<< Bus Pirate v3.b clone w/different PIC
<<< Firmware v6.1 r1676 Bootloader v4.4
<<< DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
<<< http://dangerousprototypes.com
<<< HiZ>
>>> ------------------------------------| d
<<< d
<<< VOLTAGE PROBE: 0.00V
<<< HiZ>
>>> ------------------------------------| d
<<< d
<<< VOLTAGE PROBE: 0.00V
<<< HiZ>
>>> ------------------------------------| D
<<< D
<<< VOLTMETER MODE
<<< Any key to exit
BTW, I miss possibility to have comments in BusPirate scripts...
As PSLLSP commented in #1 , the program is not very well suited for datalogging.
Review possibilities and make a first approach
As PSLLSP commented in #1 , it would be nice to be able to add comments to the scripts
I found this Python script interesting to upload and run BASIC scripts to BusPirate device. It works great for scripts that are fast. An example:
$ cat test6.bp
s
new
10 AUX 1
20 FOR I=1 TO 5
30 LET A=ADC
40 PRINT I;": ";A
50 DELAY 20
60 NEXT I
70 AUX 0
80 PRINT "WORK DONE"
list
run
exit
$ python3 buspirate.py -c /dev/ttyUSB2 test6.bp
***[ Bus Pirate scripting tool ]********************************************************************
Script file test6.bp
COM port /dev/ttyUSB2
- Opening serial port
[OK] Serial port open
- Resetting board
>>> ------------------------------------| #
<<< #
<<< RE
<<< Bus Pirate v3.b clone w/different PIC
<<< Firmware v6.3-beta1 r2151 Bootloader v4.4
<<< DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
<<< http://dangerousprototypes.com
<<< HiZ>
- Sending script file (test6.bp) - 13 lines
>>> ------------------------------------| s
<<< s
<<< HiZ(BASIC)>
>>> ------------------------------------| new
<<< new
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 10 AUX 1
<<< 10 AUX 1
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 20 FOR I=1 TO 5
<<< 20 FOR I=1 TO 5
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 30 LET A=ADC
<<< 30 LET A=ADC
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 40 PRINT I;": ";A
<<< 40 PRINT I;": ";A
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 50 DELAY 20
<<< 50 DELAY 20
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 60 NEXT I
<<< 60 NEXT I
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 70 AUX 0
<<< 70 AUX 0
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 80 PRINT "WORK DONE"
<<< 80 PRINT "WORK DONE"
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| list
<<< list
<<<
<<< 10 AUX 1
<<< 20 FOR I=1 TO 5
<<< 30 LET A= ADC
<<< 40 PRINT I;": ";A
<<< 50 DELAY 20
<<< 60 NEXT I
<<< 70 AUX 0
<<< 80 PRINT "WORK DONE"
<<< 65535 END
<<< 67 bytes.
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| run
<<< run
<<< 1: 388
<<< 2: 387
<<< 3: 387
<<< 4: 387
<<< 5: 424
<<< WORK DONE
<<<
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| exit
<<< exit
<<< Ready
<<< HiZ>
- Closing serial port
Other scripts, those run longer, are not able to finish because TIMOUT is triggered and Python session is closed. I have to run these scripts from terminal (like minicom or picocom). An example, the same script as before but it runs longer (DELAY increased from 20 to 100):
$ cat test6a.bp
s
new
10 AUX 1
20 FOR I=1 TO 5
30 LET A=ADC
40 PRINT I;": ";A
50 DELAY 100
60 NEXT I
70 AUX 0
80 PRINT "WORK DONE"
list
run
exit
$ python3 buspirate.py -c /dev/ttyUSB2 test6a.bp
***[ Bus Pirate scripting tool ]********************************************************************
Script file test6a.bp
COM port /dev/ttyUSB2
- Opening serial port
[OK] Serial port open
- Resetting board
>>> ------------------------------------| #
<<< #
<<< Ready
<<< HiZ>
- Sending script file (test6a.bp) - 13 lines
>>> ------------------------------------| s
<<< s
<<< HiZ(BASIC)>
>>> ------------------------------------| new
<<< new
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 10 AUX 1
<<< 10 AUX 1
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 20 FOR I=1 TO 5
<<< 20 FOR I=1 TO 5
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 30 LET A=ADC
<<< 30 LET A=ADC
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 40 PRINT I;": ";A
<<< 40 PRINT I;": ";A
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 50 DELAY 100
<<< 50 DELAY 100
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 60 NEXT I
<<< 60 NEXT I
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 70 AUX 0
<<< 70 AUX 0
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 80 PRINT "WORK DONE"
<<< 80 PRINT "WORK DONE"
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| list
<<< list
<<<
<<< 10 AUX 1
<<< 20 FOR I=1 TO 5
<<< 30 LET A= ADC
<<< 40 PRINT I;": ";A
<<< 50 DELAY 100
<<< 60 NEXT I
<<< 70 AUX 0
<<< 80 PRINT "WORK DONE"
<<< 65535 END
<<< 68 bytes.
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| run
<<< run
<<< 1: 388
>>> ------------------------------------| exit
<<< 2: 387
- Closing serial port
So I think it could be helpful to have a way to tell Python program to wait longer before TIMOUT disconnects it from the BP. I am not sure what is the best way to do it. The BASIC program can run on BP device for hours...
When BusPirate device is in BASIC mode, it doesn't accept commands like #
. This Python script runner is very useful to upload BASIC script to BusPirate but it doesn't detect if BusPirate is in BASIC mode and sends RESET command #
as the first command during communication with BusPirate. exit
is the command to leave BASIC mode...
$ cat test2.bp
s
10 print "Hello World!"
list
$ python3 buspirate.py -c /dev/ttyUSB2 test2.bp
***[ Bus Pirate scripting tool ]********************************************************************
Script file test2.bp
COM port /dev/ttyUSB2
- Opening serial port
[OK] Serial port open
- Resetting board
>>> ------------------------------------| #
<<< #
<<< Syntax error
<<< Ready
<<< HiZ(BASIC)>
- Sending script file (test2.bp) - 3 lines
>>> ------------------------------------| s
<<< s
<<< Syntax error
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| 10 print "Hello World!"
<<< 10 print "Hello World!"
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| list
<<< list
<<<
<<< 10 PRINT "HELLO WORLD!"
<<< 65535 END
<<< 21 bytes.
<<< Ready
<<< HiZ(BASIC)>
- Closing serial port
When BP is not in BASIC mode, in most cases, initial RESET works:
***[ Bus Pirate scripting tool ]********************************************************************
Script file test2.bp
COM port /dev/ttyUSB2
- Opening serial port
[OK] Serial port open
- Resetting board
>>> ------------------------------------| #
<<< #
<<< RE
<<< Bus Pirate v3.b clone w/different PIC
<<< Firmware v6.3-beta1 r2151 Bootloader v4.4
<<< DEVID:0x044F REVID:0x3003 (24FJ64GA004 A3)
<<< http://dangerousprototypes.com
<<< HiZ>
- Sending script file (test2.bp) - 3 lines
>>> ------------------------------------| s
<<< s
<<< HiZ(BASIC)>
>>> ------------------------------------| 10 print "Hello World!"
<<< 10 print "Hello World!"
<<< Ready
<<< HiZ(BASIC)>
>>> ------------------------------------| list
<<< list
<<<
<<< 10 PRINT "HELLO WORLD!"
<<< 65535 END
<<< 21 bytes.
<<< Ready
<<< HiZ(BASIC)>
- Closing serial port
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.