MBILI

1. Installing the Arduino IDE & Software

The first step required is to download and install, the latest version of the Arduino IDE. You will need version 1.6.5. The Arduino IDE is available both as an installer and as a zipped version.

You can find the files and installation instructions here: Arduino Software

More advanced users may wish to use Eclipse, instructions and details of the setup process can be found here: Using Eclipse with Arduino.

2. Installing the SODAQ Mbili Hardware Profile

The next step is to install the hardware profile for the SODAQ Mbili board. The Mbili board profile is available through the Arduino Boards Manager (available from IDE version 1.6.4).

In order to install the board files you will need to first add the SODAQ board manager URL
(http://downloads.sodaq.net/package_sodaq_index.json) to File->Preferences->Additional Board Manager URLs:

Next open the Board Manger via Tools->Board->Board Manger. You can then search for and install the SODAQ boards. Select and install the SODAQ AVR boards for the Mbili. Due to a current issue (Sept 2015), you must install version 1.0.0:

3. Selecting the SODAQ Mbili Hardware Profile

The Arduino IDE will now have the SODAQ Mbili board added to the list found in the menu under tools->board:

You simply need to select that hardware profile as the board that the Arduino IDE will use.

4. Configuring the Serial Port

Windows versions 7 and 8 (and 10) will normally find the right USB driver when you plug in the SODAQ Mbili for the first time. The same is also true for Mac and Linux. If your system doesn’t find the driver you will have to download the FTDI drivers from here: FTDI Drivers.

The FTDI driver adds a communication port. In Windows this is COMx (so COM1, COM8, etc.). On Linux and Mac the port name starts with /dev/tty.

You can find the list of available serial ports in the menu under Tools->Port:

You must select the communication port associated with the SODAQ Mbili board. The associated communication port is only visible in that list when the SODAQ Mbili board is connected and switched on. If you are unsure which is the correct port simply check what new port has been added after you switch the device on.

5. Configuring a Serial Monitor

You can open the built in serial monitor by pressing Ctrl-Shift-M or through the menu Tools->Serial Monitor. The default setting does not add CR/LF to any commands you send. You will want to change this using the drop down options shown below:

Alternatively, you can use a terminal emulator such as PuTTY. The download page can be found here: PuTTY Download and you can find instructions on the configuration settings here: PuTTY Configuration.

Note:  The Arduino IDE will automatically close the built in serial monitor before uploading a sketch. If you are using a terminal emulator you must close the session before you can upload a sketch. If you do not, you will get an error message stating that access is denied to the communications port (it is busy due to another active session).

Additional Note: Whenever a terminal session is opened, a reset command is sent to the device. Your uploaded sketch will then restart and you will see any messages that might be displayed at startup. There is no need to rush to try and open the serial monitor immediately after uploading your sketch.

Loading and Running a Basic Demo

You are now ready to upload and run your first sketch. Ensure that the SODAQ Mbili board is connected and switched on, and that you have configured it as shown above.

Simply copy and paste the following code into a new sketch.

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(57600);
  Serial.println("Starting...");
}

void loop() 
{
  // put your main code here, to run repeatedly:
  Serial.println("Hello World");
  delay(1000);
}

Click  “Compile” to optionally compile and test the code and then “Upload”  to compile and upload it to the SODAQ Mbili board.

If you open the built in serial monitor by pressing Ctrl-Shift-M you should see a startup message displayed, and then “Hello World” displayed, repeatedly, at one second intervals.

a b c d e f g h i j k l m n o p q r s t
a Switched Grove row
b Always on Grove row
c Switched Grove row power LED
d 6 pin ICSP header
e 16 Mbit serial flash
f ATMega 1284P miicrocontroller
g Two user programmable LEDs
h DS3231 real time clock
i Super capacitor for the real time clock
j Reset switch
k JTAG header
l On/Off switch
m Header for an external On/Off switch
n FTDI chip
o Bee socket
p GPRSBee power connector
q Battery connector
r Battery power draw measurement jumper
s Solar panel connector
t USB Connector

The Grove connectors in the Switched row (a) share a common switched power line. This is controlled through the digital pin GROVE_PWR (D22). These sockets are ideal for sensors which need to be powered down between readings. The LED (c) is lit when this row is powered on.

The Grove connectors in the Always On row (b) are always powered on. These sockets are for sensors that need to be powered permanently or for sensors which have a low power draw.

The standard 6 pin ICSP header (d) can be used to program the SODAQ Mbili, including loading or reloading the bootloader onto the board.

Just like the SODAQ Moja the SODAQ Mbili has 16 Mbit serial flash (e).

The SODAQ Mbili has a ATMega 1284P microcontroller (f) and two user programmable LEDs (g).

The DS3231 real time clock chip (h) is now powered by a super capacitor (i). This allows the real time clock to continue ticking for several days after the battery has been removed.

The reset switch is located at (j).

The SODAQ Mbili now has a JTAG header (k). This can be used for debugging purposes.

The On/off switch is located at (l) and a header for an external switch at (m).

For the USB connection a FTDI chip (n) has been used again. This is powered off completely when no USB cable is connected.

The Bee socket (o) is now connected to a separate UART. This means that the communication module in the Bee socket can be used while also sending debug output over the USB port.

Specifically for the GPRSBee module, a separate power connector (p) has been added. This allows for software control over powering the GPRSBee module on and off.

The battery connector (q) and the solar panel connector (s) are the same as on the SODAQ Moja, A jumper (r) has now been added which can be used to measure the power draw from the battery. This jumper needs to be closed when it is not being used for measuring.

The USB connector is located at (t).

(1) The most significant change on the back side of the board is that of the inclusion of a MicroSD card slot. The extra memory and program space of the ATMega 1284P, can easily accommodate a FAT file system and the use of the a MicroSD card for data logging.

Jumpers

(2) Can be used to connect the Bee socket to Serial instead of the default Serial1.
(3) Can be used to enable the card detect functionality of the MicroSD card slot.
(4) Can be used to allow for ‘over the air programming’ through a Bee module. This requires that the Bee socket is connected to Serial using Jumper (2).
(5) Can be used to disconnect the Charge indicator LED to minimise power consumption.
(6) Can be used to disconnect the Switched Grove LED to minimise power consumption.
(7) Allows the connection of either the ASSOC pin of a Bee module or the Ring Indicator line of the GPRSBee to an I/O pin.
(8) Allows the RTC to be used as an interrupt device.
(9) Allows the RTC to be used as a 32kHz clock source.

Schema rev.3 (beta)

Schema rev.4

Schema rev.5

We believe in the Arduino IDE:

The Arduino language uses C/C++ syntax and includes a set of C/C++ methods which can be called from your sketch code. Details of these methods and other aspects of the language can be found here: Arduino Language Reference.

Additional libraries can also be installed as required. Information about Arduino libraries and how to install them can be found on the following page: Arduino Libraries Guide 

For general reference on C/C++ syntax and language see:
C/C++ Syntax & Language Reference on cprogramming.com

Structure

A typical Arduino sketch consists of three main sections:

  • Declarations of global constants, variables and objects: Used to define any global values, variables, or objects which are used throughout the sketch.
  • The setup() method: This method is called once when the sketch is started (whenever the device is powered on or reset).  It is used for setup and initialisation.
  • The loop() method: This method contains the core functionality of the sketch. It is called consecutively while the sketch is running.

Example Sketch

//Global constants, variables and objects
#define START_MSG "Running Setup()..."
#define LOOP_DELAY 500
int loopCount = 0;

//Initialisation
void setup() 
{
   Serial.begin(57600);
   Serial.println(START_MSG);
}
//Execution loop
void loop() 
{
   loopCount++;
   Serial.println("Loop() has run " + String(loopCount) + " times");
   delay(LOOP_DELAY);
}

Sketch Code Breakdown

Globals

Here two constants are defined (using the preprocessor directive #define). One of them defines the message which will be displayed at startup and the other defines the effective frequency that the loop() method will run at. Defining constants in this way allows for easy modification of these values. This is particularly true in cases where the constants are referenced multiple times throughout a sketch. We also declare a global variable, loopCount, of type int and initialize it to 0.

//Global constants, variables and objects
#define START_MSG "Running Setup()..."
#define LOOP_DELAY 500
int loopCount = 0;

setup()

Here we first open the serial connection using the method Serial.begin(). We then send a message using the Serial.println() method, passing it the string constantSTART_MSG we defined above.

//Initialization
void setup() 
{
   Serial.begin(57600);
   Serial.println(START_MSG);
}

loop()

Here we increment the value stored in loopCount using the ++ operator. We then display a message which shows how many times the loop() method has been called so far. Finally we call the delay() method which only returns after the specified number of milliseconds have elapsed. This effectively controls the execution frequency of the loop() method.

//Execution loop
void loop() 
{
   loopCount++;
   Serial.println("Loop() has run " + String(loopCount) + " times");
   delay(LOOP_DELAY);
}

If you load the sketch onto the SODAQ Mbili board and then open the Serial Monitor you should see output that looks similar to this:

Build your own touch sensor:

Now that we have got you started on the basics of the Arduino language, let’s start hooking up a sensor. In this example we will demonstrate how to use a Touch Sensor and a Vibration Motor. This example is another demonstration of the use of the digital pins for both input and output. A digital signal is received from the Touch Sensor and is used to activate and deactivate the Vibration Motor.

This could be applied to the creation of a toy for children such as a robot cat that responds to touch by vibrating.

Required Components

  • SODAQ Mbili Board
  • 0.5W Solar Panel
  • 1aH Battery Pack
  • Grove – Touch Sensor
  • Grove – Vibration Motor
  • 2x Grove Cable (any length)

Required Libraries

  • none

Hardware Setup

You should refer to both the board diagram and Grove sockets page for additional information.

  1. First, plug the Vibration Motor into the socket for the digital pins D4 D5.
  2. Then, plug the Touch Sensor into the Grove socket for the digital pins D20 D21.
  3. Next, plug the 0.5W solar panel and the 1A LiPo battery into their respective sockets.

Turn on the SODAQ Mbili board, compile and upload the following sketch from the Arduino IDE onto the SODAQ Mbili board, and then unplug the USB cable from the computer when it has completed the upload.

Sketch Code

#define MOTOR_PIN 4 //Use digital pin 4 for the vibration motor
#define TOUCH_PIN 20  //Use digital pin 20 for the touch sensor

void setup() 
{
  //Set the digital pin modes
  pinMode(MOTOR_PIN, OUTPUT);
  pinMode(TOUCH_PIN, INPUT);
}

void loop() 
{
  //Read the current state of the touch sensor
  int sensorValue = digitalRead(TOUCH_PIN);

  if(sensorValue == HIGH)
  {
    //If the sensor is reading HIGH switch on the vibration motor
    digitalWrite(MOTOR_PIN, HIGH);
  }
  else
  {
    //If not, turn the vibration motor off
    digitalWrite(MOTOR_PIN, LOW);
  }
}

When you touch the sensor, you should feel the vibration motor activate.

Sketch Code Breakdown

Globals

Here we specify the digital pins we will use for both the Vibration Motor and the Touch Sensor.

#define MOTOR_PIN 4 //Use digital pin 4 for the vibration motor
#define TOUCH_PIN 20  //Use digital pin 20 for the touch sensor

setup()

Here we set the pin mode for the two digital pins we are using. This is done through a call to pinMode() with the first parameter specifying the pin to be set and the second parameter specifying the mode for that pin. The Vibration Motor pin is set to OUTPUT mode while the Touch Sensor pin is set to INPUT mode.

void setup() 
{
  //Set the digital pin modes
  pinMode(MOTOR_PIN, OUTPUT);
  pinMode(TOUCH_PIN, INPUT);
}

loop()

Here we read the state of the Touch Sensor by reading a value from the digital pin that it is connected to. This is done using the digitalRead() method which returns a value matching the built in constants of HIGH or LOW. We then modify the state of the output pin connected to the Vibration Motor using the digitalWrite() method, passing the value returned from the Touch Sensor. An if/else conditional is used to determine whether to switch the Vibration Motor on or off.

void loop() {
 //Read the current state of the touch sensor   
 int sensorValue = digitalRead(TOUCH_PIN);   
  if(sensorValue == HIGH)   { 
      //If the sensor is reading HIGH switch on the vibration motor      
       digitalWrite(MOTOR_PIN, HIGH);   
 }   else   { 
       //If not, turn the vibration motor off        
       digitalWrite(MOTOR_PIN, LOW);   
 } 
}