Moja

Switching the board on

The only switch on the SODAQ Moja board is an on/off switch. In off state the solar charge circuit is still active and the real-time clock is still powered. Make sure that also when programming the board the switch is in the ON position. Next to the switch there is a two pin header for an external on/off switch. If you want to use the external on/off switch make sure the switch is in off state.

Windows 7 and 8 normally find the right USB driver when you plug in the Moja for the first time. The same is true for Mac and Linux.If your system doesn’t find the driver you will have to download the FTDI from:

www.ftdichip.com/drivers/vcp.htm

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

The SODAQ board can be programmed with the Arduino IDE. The latest version of Arduino IDE can be found at www.arduino.cc. The SODAQ board is tested with Arduino IDE version 1.0.5. Before you can program the SODAQ you have to select the right board and port settings. You can select the board by going to Tools > Board > Arduino Pro or Pro Mini(3.3V, 8 MHz)w/ATmega328.

Next, make sure you select the right serial port (examples for Mac, Windows and Linux):

Mac

Windows

Linux

In Arduino IDE you can begin with a simple sketch like LED blink. Go to File > Examples > 01.Basics > Blink. This sketch needs to be modified, because the SODAQ board doesn’t have a LED on pin 13, but has a LED on pin 6 instead. Pin 6 is normally used for switching power to the Switched row of Grove connectors, but for now we just use it because it has an LED too. Now if you look at the first line that has colored text (Should be line 10 if you load the example) you see “int led = 13;”. Change the number ‘13’ to ‘6’ and upload the sketch to the SODAQ board using the right settings mentioned above. (or just copy the code below:)

int led = 6;
void setup() {
pinMode(led, OUTPUT);

}
void  loop() {
digitalWrite (led, HIGH);
delay (1000);
digitalWrite (led, LOW);
delay (1000);
}

When programming the SODAQ board, always make sure that there is no bee module in the bee slot. If a bee module is plugged in while programming the SODAQ board it may cause the programming to fail. This is because USB connector and the bee module are using the same connections for communication.

Grove Sockets

The SODAQ board has two rows of grove connectors. They both contain the same I/O pins but one row can be turned on/off in software. The switched row can be used to reduce the energy consumption of some sensors. Make sure the maximum current of all sensors in the switched row is not greater then 115 mA. The switching of this row is done by actually switching the ground connection on/off. Therefore if you are using the switched row with a cable, make sure you are not using any other ground connection then this cable. Otherwise the switching will not have effect and the attached device will always be powered.

Real Time Clock (RTC) DS3231

The real-time clock is connected with the I2C lines of the ATmega328p. The RTC keeps information about  seconds, minutes, hours, day, date, month and year.But this chip can also measure temperature with a ±3°C accuracy.

 Setting up DS3231 in arduino project

To be able to work with the DS3231 in your arduino project you need to include the following libraries:

Wire.h
Sodaq_DS3231.h

The code to run in the arduino setup function:

Wire.begin();  
rtc.begin();

Now you are ready to start using the DS3231 in your code.

Reading time from the DS3231

To be able to get data from the RTC you have to something like this:

now = rtc.now();
uint32_t ts = now.getEpoch();

The epoch timestamp is a 4bits timestamp. But that isn’t the only thing you can get from it, you are also able to ask each separate item with its own function:

 char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
 Serial.print(now.year(), DEC);
 Serial.print('/');
 Serial.print(now.month(), DEC);
 Serial.print('/');
 Serial.print(now.date(), DEC);
 Serial.print(' ');
 Serial.print(now.hour(), DEC);
 Serial.print(':');
 Serial.print(now.minute(), DEC);
 Serial.print(':');
 Serial.print(now.second(), DEC);
 Serial.print(' ');
 Serial.print(weekDay[now.dayOfWeek());

Here is a function that is handy to be able to set up the RTC

void adjustDate(int year, int month, int date, int hour, int min, int sec, int weekday){
DateTime dt(year, month, date, hour, min, sec, weekday);
rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above 
//Serial.println(rtc.now().getEpoch());//debug info
}

Reading from the temp sensor

 To read data from the temp sensor you need to use the following code:

rtc.convertTemperature();            //convert current temperature into registers
float tempFloat = rtc.getTemperature(); //read registers and display the temperature

1. Flash memory (AT45DB161E)
2. Microcontroller (ATmega328P)
3. FTDI chip (FT232RL)
4. Real-time clock (DS3231)

Specifications

  • Atmega Microcontroller running at 3.3V and 8MHz

  • Arduino Compatible

  • Power supply by LiPo battery (3.7V) or USB cable

  • Solar charge controller with JST connector for Solar Panel up to 2.5W

  • Battery Monitor

  • DS3231 Real Time Clock and Temperature sensor, clock backup powered by LiPo battery

  • 8 MBit data flash module (AT45DB)

  • Micro USB connector

  • 12 Grove connectors connecting Digital, Analog and I2C pins

  • On/Off switch. With the switch in Off position the solar charge circuit is still active and the RTC clock is still powered.

  • ICSP programming header

  • Bee socket for Xbee, GPRSbee or other bee style modules

Using a Button to Activate a Buzzer

 

In this tutorial, you learn how to create an alarm noise on a buzzer and how to activate it with a button.

Required components:

  • SODAQ Moja
  • 0.5W Solar Panel
  • 1aH battery pack
  • Grove – Buzzer
  • Grove – Button

First, plug the buzzer into the D4/D5 pin in the always on row. Then, plug the button int the D2/D3 pin in the always on row.

Next, plug the 0.5W solar panel and the 1A LiPo battery into the respective sockets (see http://www.sodaq.net/#!getting-started/c21ma for a board diagram)

Turn on the SODAQ board, compile and upload the following sketch from the arduino IDE onto the SODAQ Board, and then unplug the USB cable from the computer when it is working:

const int buttonPin = 2; //set pin 2 for the button const
int buzzerPin = 4; //set pin 4 for the buzzer
int buttonState = 0; //buzzer starts off

void setup()
{
 //define the output and input in the  equation here
 pinMode(buzzerPin, OUTPUT);
 pinMode(buttonPin, INPUT);
}

void void loop()
{
 buttonState = digitalRead(buttonPin);

 if (buttonState == HIGH) {
           // turn buzzer on:
        digitalWrite(buzzerPin, HIGH);
 }
else {
           // turn buzzer off:
        digitalWrite(buzzerPin, LOW);
 }
}