November 5th, 2012 | Published in Research
ParticleBasic is an attempt to simplify the programming model of the Particle Computer and enable rapid prototyping of applications. It therefore consists of two major components:
- A small scale VM on the Particle Computer and an interpreter running on top of it.
- A compiler for the development platform (written in JAVA) that generates byte code for the VM.
- Plus a small helper application that simplifies the upload of the byte code to the Particle.
The workflow then is very simple:
Write your application in ParticleBasic -> Compile it to byte code with the ParticleBasic compiler -> Upload the byte code to the Particle.
This approach has many advantages:
- The byte code is much smaller than an ordinary program code generated by SDCC or CCS PIC-C and therefore is transfered much faster.
- Less error prone than coding in C or assembler.
- Easier debugging.
- Concept of multiple code slots, i.e. you can upload multiple programs and choose which program should be run.
- Get the ParticeVM hex file and use OtAP or a flash programmer like Galep to program your Particle Computer. This version was tested on the Particle 2/10 core board.
- Download the compiler (a batch file is available that simplifies the invocation of the compiler).
- Download the upload helper utility and accompanying start script.
- If necessary adapt the path to to the jar files in both script files.
- A JRE (preferably 1.4.x and higher) needs to be installed
- ParticleAnalyzer is not necessary but highly recommended to keep track of the Particle network traffic.
- Ready ;-)
The best way to get started is to have a look at this small example ParticleBasic program. The Syntax is very similar to VisualBasic. The compiler understands
For and While loops and If Then Else statements. Comments start with a single quote ‘ and end at the next line break.
Compilation: The syntax is “pbcompiler.bat filename.bas”. After a successful run a file named “filename.bin” is created. If you don’t use the script you can invoke the compiler with the command “java -jar pbcompiler.jar filename.bas”.
Upload: The syntax is “send filename.bin particleId”. Filename.bin is the file created by the ParticleBasic compiler, particleId identifies the Particle you want to program, an example Id looks like 10.0.1.0.220.127.116.11. If you don’t know the ID of the Particle you can use the ParticleAnalyzer to search for Particles. If you don’t use the given script you can start the upload utility with the ommand “java -jar send.jar filename.bin particleId”. After a successful upload the VM should load the received code into its memory and execute it. As the byte code is stored in the flash memory it is preserved during reboots of the Particle Computer.
- Send bugreports to email@example.com.