Skip to content

First program

Info

Brian currently supports user programs in micro python. Support for more languages is coming soon. [ ]

The minimal setup does not require any software installation on your computer. However, for effective work, there are some programs recommended (see IDE and Debugging)

IDE

IDE is a code editor software, which helps you with the development. There are plentiful options available. Choose any IDE which supports writing python code. If you do not wish to use an IDE, any text editor will work just fine. We recommend using PyCharm IDE from JetBrains.

We provide a reference documentation in a .pyi which IDEs can load and understand. Please download the package here.

Writing your first program

Open a text editor of your choice and create a program hello.py. The file should have this content:

print("Hello world!")

For now, we will use only this very simple program. It is supposed to print the text "Hello world!" and do nothing else. We have provided some sample programs for your convenience.

Uploading the program to Brian

There are two options ready, one planned:

Using SD card

Put an SD card to your computer, and copy this file anywhere on the card. Eject the card and insert it to Brian. Thats it. Your program is now ready to run. Please note that for each program update, the card should be ejected safely via a Eject SD button in the SD card view. Otherwise there is a risk of file system corruption.

Connecting SD card via USB

Insert an SD card to Brian and leave it there. SD card is required with this option as well, because all programs are stored and loaded from the sd card.

Connect Brian to your computer using a USB cable. Turn on Brian and it should register as a mass storage device. You see the contents of the SD card and you can copy files from your computer directly to Brian (the SD card) like this. Please note that you will see Brian connected as a mass storage device only when it is powered on and no user program is running.

Copy the file hello.py to Brian. That's it.

Do not develop from the mounted device

It may be tempting to edit and work on your files directly from the connected mass storage device. This workflow is discouraged, because it disconnects from the computer every time the program is running and this may confuse the code editor, when the files are suddenly disappearing and appearing under its hands. You are also at risk that in the case of the sd card file system corruption, you will loose all your data and won't have any backup.

Info

Mounting as an SD card works only if this feature is enabled (default behavior). Read choosing USB function.

Wireless transfer

[ ] Brian contains hardware for communicating over WiFi networks. The software part is not implemented yet. It will be possible, to connect to Brian over WiFi and transfer files wirelessly. It will be also possible to communicate with the running program over WiFi.

Running the program

Navigate to your file in the SD card file explorer and select the file. Select the main file. This will open a screen with more details and the first option is to run the program. Please note that when running a program, the computer mass storage device disconnects.

Success

Congratulations! You have successfully instructed Brian to run your first piece of code, which you just programmed. For more possibilities, please read the API reference

Stopping the program

It is the programmers's responsibility to provide a mechanism to stop the program (e.g. wait for a specific button press). There are several mechanisms to choose from:

  • The program will end, when there is nothing else to do. Our simple hello.py will print Hello world! and stop, because it is at the end of the file.
  • The program will end upon a standard API call: sys.exit()
  • Brian will send a KeyboardInterrupt to the program when left and right button are pressed simultaneously. It doesn't matter if you press top or bottom buttons. Usually, the program ends after the keyboard interrupt, but in some situations, the program may choose to ignore it.
  • Force shut down: If your program is unresponsive and you have disabled the KeyboardInterrupt option, or it is being ignored, you can remove the micro SD card. This will kill the program (as it is run from the card). Please note, that this mechanism should not be used in a normal scenario, as it risks corrupting the files on the SD card. You can also force-power-off entire Brian by disconnecting the USB cable and pressing all four buttons simultaneously.

Program output

All python print statements are shown on the Brian screen. The print results are scrollable (via the knob), but the history buffer is limited to 1500 lines for performance reasons.

At the same time, the print output is streamed to a connected console, if enabled (read choosing USB function.) You can read this output using any standard serial console, connected to the correct port. Brian communicates at baud rate of 115200.

Choosing USB function

USB can function in one of two modes:

To change the mode, navigate from main menu to Settings and Use USB for.... Then select a desired mode. When changing the mode, please remove the USB if attached and reboot Brian. Otherwise the computer may not enumerate the type of the device correctly.

When the "USB - reboot pending" icon (USB - reboot pending) is shown, it means that the selected mode is different than the one currently used and the effect will take effect only after the reboot with disconnected USB.

[ ] Support for both modes at the same time is planned, but not implemented yet.