qbcan software installation

From Open Cosmos :: Documentation
Jump to: navigation, search


In case you have any problem during the assembly or operations please post your questions into the Open Cosmos community so all the users can benefit from the content.

Software Installation

The Arduino Pro Micro microcontroller is the core component of the qbcan but it will need to be programmed in order to perform its mission. In this section you will learn to set-up a development PC with which you will be able to develop and upload code to your qbcan. The following steps will guide you through the whole process.

Arduino is programmed in C.

Arduino is a very popular rapid-prototyping board with many tutorials and forums available online that can be very helpful when getting started in this environment.

If you do not have any experience in programming C and/or Arduino we recommend you to watch the Jeremy Blum Arduino tutorials.

Install the Arduino IDE

The core of the qbcan is an Arduino Pro Micro. Arduino is a family of open-source microcontroller boards widely used for hobby projects. In order to program the Arduino you need to install its Integrated Development Environment (IDE):

Using this IDE you will be able to compile the code and upload it to the Arduino.

Drivers and board selection in the Arduino IDE

Drivers should automatically be installed when plugging the qbcan to your PC via USB. In some instances, you might get the message Unknown USB device. In which case it might be necessary to manually install the drivers.

Intructions to manually install the drivers for Arduino Leonardo

qbcan compact/modular board selection
  • Select the correct port in Tools > Port.
  • Go to Tools > Board and select Arduino Leonardo.
  • Go to check your installation section.

If Arduino Leonardo does not work for the qbcan modular, follow the steps below to install Arduino Pro micro drivers:

alternative qbcan modular board selection and drivers installation if needed

For the qbcan modular, you can try to interface with it using the Arduino Leonardo board selection detailed in the section above. If this option works, you can continue to the next step.

If when plugging the Arduino Pro Micro to your computer, the board is not recognised, you will need to install the Pro Micro drivers. Follow the following steps for this:

  • Windows, Mac and Linux: Follow this guide to install the drivers. Only from Arduino IDE 1.5 and up. You can update the Arduino IDE in the Arduino software page.

This method will automatically install the drivers when you plug the Arduino Micro Pro. If this method does not work due to permission restrictions, a more manual process can be followed:

  • Alternative for Windows users: Follow this guide to install the drivers for Windows
  • Alternative for Mac/Linux users: this guide to install the drivers for Mac/Linux.

The board selection for qbcan modular should be performed as following:

  • Go to Tools > Board and select Sparkfun Pro Micro.
  • Under Tools > Processor select ATmega32U4 (5V, 16MHz).
  • Go to check your installation section.

Check your installation

Now you are ready to start programming qbcan and it is a good time to check that everything is correctly installed.

  • Test the installation, plug the computer into the qbcan compact or Arduino Pro micro on the qbcan modular using the micro USB cable.
  • Download this sketch as a test file. The test file is for Arduino Micro Pro but it also works for Arduino Leonardo.
  • Open it in the Arduino IDE.
  • Select the board as specified in the board selection section above.
  • Click verify to compile.
  • Click upload to upload.

You will see two LEDs blinking and if you open the serial monitor in Tools > Serial monitor you will see the board sending data via the serial port.

If that works, your qbcan is ready and you can start using it as your CanSat bus.

Download and Install the qbcan Library

qbcan is distributed with an Arduino Library that helps you interface with the transceiver RFM69 and the pressure and temperature sensor BMP180. In order to install the library:

  • Go into the Arduino IDE and click to Sketch > Import or include Library > Add Library.
  • Go to the folder where you have saved the qbcan library, browse to qbcan.zip and accept.
  • Close and start again the Arduino IDE for the library to be loaded.

To make sure that the library has been correctly installed, check that the qbcan examples can be found in File > Examples > qbcan.

Click here to download the qbcan library

Test qbcan using the qbcan Library examples

The qbcan Library contains examples you can use to check that the whole system works properly. In order to access the examples in the Arduino IDE:

  • Go to File > Examples > qbcan.

You can find a CanSat and a ground station examples. The CanSat example measures the temperature and pressure and transmits them to the ground station.

The Ground Station example can be uploaded in another qbcan that then would take the role as a Ground Station, receiving the data from a qbcan acting as the CanSat. You can progress now to upload each code to a qbcan, using the steps defined in Upload any file to your qbcan section.

Tip: Open two Arduino IDE instances (Windows users click again in the Arduino IDE shortcut to open another independent session). This way you can set up one Arduino IDE in one qbcan for the CanSat side and another one in another qbcan acting as the Ground Station.

Mac users will need to use the command line if they want to have two instances of the same program opened. For this, go to command line and just write open -n -a /Applications/Arduino.app/ or with the right path to the application (you might have it in your desktop or downloads).

Once uploaded each code, you can open the serial monitor, to see the data coming in or going out.

To do so:

  • Select the COM port you want to monitor Tools > Port.
  • Open the serial monitor in Tools > Serial Monitor.
  • Set the speed of the serial connection to 9600 baud (this value depends on how you define the serial connection in the qbcan code. See the Using the RFM69 transceiver section).

In order to try these examples, you will need to have a completely assembled qbcan modular kit (qbcan compact is delivered already assembled). We encourage you to use these examples as starting point for your projects.

Upload any file to your qbcan

  • Open the desired file in the Arduino IDE.
  • Select the board as specified in the board selection section above.
  • Select the right COM port in Tools > Port
  • Click verify to compile (Arduino IDE does not always compile properly when clicking upload so it is strongly advised to click verify) before uploading.
  • Click upload to upload.

qbcan Library manual

A very important part of the qbcan is the software library. This library provides an easy-to-use interface to the transceiver and the pressure and temperature sensor. In Download and Install the qbcan Library section a step-by-step guide on how to install the qbcan library can be found.

In this sections there are some tips exposed regarding the usage of the libraries and some introductory samples of useful code to be implemented in your mission.

Library basics

To use the library you will need to include the qbcan library and the SPI.h and Wire.h libraries at the beginning of your code, so that the qbcan can have access to the SPI and I2C buses.

  2. //Include the required libraries
  3. #include <qbcan.h> //Core qbcan library
  4. #include <Wire.h> //I2C bus library
  5. #include <SPI.h> //SPI bus library

The SPI.h and Wire.h libraries are part of the Arduino IDE and thus no installation is required. The library qbcan.h needs to be placed at the top of the sketch.

Using the BMP180 pressure and temperature sensor

The qbcan library provides a class to interface with the BMP180 pressure and temperature. To create the sensor object use the following snippet.

  2. //Create the pressure and temperature sensor object
  3. BMP180 bmp;

Use this piece of code just after the library #include. This will create the sensor object.

On the setup() function you will need to initialise the sensor. You can do this with the following piece of code:

  2. void setup()
  3. {
  5. //Initialize serial connection for debugging
  6. Serial.begin(9600);
  8. // Initialize pressure sensor.
  9. if (bmp.begin())
  10. Serial.println("BMP180 init success");
  11. else
  12. {
  13. //In case of error let user know of the problem
  14. Serial.println("BMP180 init fail (disconnected?)\n\n");
  15. while(1); // Pause forever.
  16. }
  18. }

After initialising the sensor it is ready to measure. To measure temperature and pressure you can use the following piece of code (note that the temperature unit is degrees Celsius and the pressure unit is mbar).

  2. //Declare temperature and pressure variables
  3. double T,P;
  5. // Get a new temperature and pressure reading
  6. bmp.GetData(T,P)

After taking the measurement you can send the data to the serial port to be displayed in your PC serial monitor with the following piece of code:

  2. //Display data
  3. Serial.print("Absolute pressure: ");
  4. Serial.print(P,2);
  5. Serial.println(" mb.");
  6. Serial.print("Temperature: ");
  7. Serial.print(T,2);
  8. Serial.println(" deg C.");

Using the RFM69 transceiver

The library also provides a class to interface with the transceiver. You can create the object as follows.

  2. //Radio object
  3. RFM69 radio;

Before initialising the RFM69 object on the setup() function it is useful to define some of the transceiver parameters as follows:

  2. //Radio Parameters
  3. #define NODEID 2 //unique for each node on same network
  4. #define NETWORKID 100 //the same on all nodes that talk to each other
  5. #define GATEWAYID 1 //Receiving node
  7. #define ENCRYPTKEY "sampleEncryptKey" //The same on all nodes!

The NETWORKID can be set from 0 to 255 and that changes the physical channel used for the link (i.e. the frequency). Although in this guide the NETWORKID is considered a parameter, it can be changed during runtime. For this, you will need to re-initialise the library.

The NODEID is the node in a particular channel and can be set from 1 to 255. Therefore, we can have up to 255 qbcan operating in the same frequency, although they cannot transmit at the same time. Messages are generally send to a specific node and that is the GATEWAYID. So if you are configuring a transmitter/receiver make sure that you are transmitting to the correct node. Also a receiver can sniff all the packets in a network, thus receiving all traffic in that network independently if the messages where addressed to that particular node. To configure the radio on the setup you can just use the following code.

  2. void setup() {
  4. //Initialize serial connection for debugging
  5. Serial.begin(9600);
  7. //Initialize radio
  8. radio.initialize(FREQUENCY,NODEID,NETWORKID);
  9. radio.setHighPower(); //Use the high power capabilities of the RFM69HW
  10. radio.encrypt(ENCRYPTKEY);
  11. Serial.println("Transmitting at 433 Mhz");
  13. }

To send data through the network.

  2. //Send Data
  3. char payload[50];
  4. sprintf(payload,"T: %d C, P: %d mb.",(int)T,(int)P); Serial.print(payload);
  5. radio.send(GATEWAYID, payload, 50);
  6. Serial.println("Send complete");

In the radio.send() function, the last argument is the length of the message to be transmitted In the example above the the message payload is 50 bytes long and we are sending it in full although the actual message is not that long (so it could be optimised).

In order to receive data transmitted through the network, the following piece of code can be used:

  2. if (radio.receiveDone())
  3. {
  4. for (byte i = 0; i < radio.DATALEN; i++)
  5. Serial.print((char)radio.DATA[i]);
  6. }

Use radio.promiscuous(true); to activate the "promiscuous" mode to listen all packets from the network in use.

There are also some other functions that you may find useful when receiving messages:

radio.SENDERID - returns the sender node id.

radio.TARGETID - returns the message target node id (in case you are sniffing all the packets in the network).

radio.RSSI - returns the received signal strength (RSSI).


The provided library contains examples that can help you get started. The examples can be found in the Arduino IDE by clicking on File > Examples > qbcan. There is one example, labelled as CanSat that transmits data and another one labelled as GroundStation that will receive it.