Qbcan software installation

From Open Cosmos :: Documentation
Revision as of 09:59, 15 August 2016 by Jordi (Talk | contribs) (Created page with "{{Lowercase title}} == Software Installation == The Arduino Pro Micro microcontroller is the core component of the qbcan but it will need to be programmed in order to perfor...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Template:Lowercase title

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.

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). On the Arduino software page you can find the latest IDE package. Download the software version dedicated to your platform and install it. Arduino is programmed in C. Using this IDE you will be able to compile the code and upload it to the Arduino. 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 Pro Micro drivers

The Arduino IDE works out of the box with most Arduino boards, but not with the Arduino Pro Micro. In order to make it work additional drivers need to be installed. Follow this guide to install the drivers for Windows or this guide to install the drivers for Mac/Linux. This guide follows a different approach which is valid for both Windows and Mac/Linux. Follow it in case the first one is not successful.

Board selection in the Arduino IDE

Once the driver has been correctly installed, the right board in the Arduino IDE can be selected. Go to Tools > Board and select Sparkfun Pro Micro. Under Tools > Processor select ATmega32U4 (5V, 16MHz). Select the correct port in Tools > Port. Since Arduino Pro Micro is very similar to Arduino Fio or Leonardo, in some cases selecting the Arduino Fio or Arduino Leonardo boards in the IDE (in Tools > Board) will also work. Therefore, if you are having problems installing the drivers, you can also try this option.

Check your installation

Now you are ready to start programming Arduino Pro Micro and it is a good time to check that everything is correctly installed. In order to test the installation, you do not need to have the qbcan assembled. Just pick the Arduino Pro Micro and plug it to your computer using the micro USB cable. Using Arduino IDE you can upload this sketch to the Arduino to check that the whole set-up is working (you will see two LEDs blinking). If that works, your qbcan is ready and you can start using it as your CanSat bus.

Download and Install the qbcan Arduino 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 Library > Add Library. Then go to the folder where you have saved the qbcan library, browse to qbcan.zip and accept. You will then need to 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, click on File > Examples > qbcan. You can find a CanSat example that measures temperature and pressure and transmits them to the ground station.

The GroundStation example can be used with another qbcan to receive this data. To do so, open the serial monitor in Tools > Serial Monitor and 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).

If you run each of the codes on two different qbcan you will be able to send and receive data and test the sensors. In order to try these examples, you will need to have a completely assembled qbcan kit. We encourage you to use these examples as starting point for your projects.


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 Sec. 3.2 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.