Difference between revisions of "Qbcan software installation"

From Open Cosmos :: Documentation
Jump to: navigation, search
(Test qbcan using the qbcan Library examples)
Line 38: Line 38:
 
If that works, your qbcan is ready and you can start using it as your CanSat bus.
 
If that works, your qbcan is ready and you can start using it as your CanSat bus.
  
==== Download and Install the qbcan Arduino Library ====
+
==== 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.
 
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:
 
In order to install the library:
Line 65: Line 65:
 
A very important part of the qbcan is the software library.
 
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.
 
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 [[#Download and Install the qbcan Library|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.
 
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.

Revision as of 10:48, 19 October 2016


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 computer 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.

  • Windows users: Follow this guide to install the drivers for Windows
  • Mac/Linux users: this guide to install the drivers for Mac/Linux.
  • Alternative approach for Windows, Mac and 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.

  • Test the installation, plug the computer into the qbcan compact or Arduino micro on the qbcan modular 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 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.
  • 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:

  • 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
  • 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 modular kit (qbcan compact is delivered already assembled). We encourage you to use these examples as starting point for your projects.

Library

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.

  1.  
  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
  6.  

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.

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

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:

  1.  
  2. void setup()
  3. {
  4.  
  5. //Initialize serial connection for debugging
  6. Serial.begin(9600);
  7.  
  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. }
  17.  
  18. }
  19.  

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).

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

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:

  1.  
  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.");
  9.  

Using the RFM69 transceiver

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

  1.  
  2. //Radio object
  3. RFM69 radio;
  4.  

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

  1.  
  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
  6.  
  7. #define ENCRYPTKEY "sampleEncryptKey" //The same on all nodes!
  8.  

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.

  1.  
  2. void setup() {
  3.  
  4. //Initialize serial connection for debugging
  5. Serial.begin(9600);
  6.  
  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");
  12.  
  13. }
  14.  

To send data through the network.

  1.  
  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");
  7.  


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:

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

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).

Examples

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.