Waspmote Utilities Programming Guide
Waspmote Utilities Programming Guide
Programming Guide
Index
Document Version: v4.0 - 02/2013
Libelium Comunicaciones Distribuidas S.L.
INDEX
1. Introduction.......................................................................................................................................... 4
2. USB Library........................................................................................................................................... 4
2.1. Waspmote Libraries......................................................................................................................................................................4
2.1.1. Waspmote USB Files.....................................................................................................................................................4
2.1.2. Constructor......................................................................................................................................................................4
2.1.3. Pre-Defined Constants................................................................................................................................................4
2.2. Initialization....................................................................................................................................................................................4
2.3. Reading data...................................................................................................................................................................................4
2.4. Printing data ..................................................................................................................................................................................5
3. Utilities Library..................................................................................................................................... 7
3.1. Waspmote Libraries......................................................................................................................................................................7
3.1.1. Waspmote Utilities Files .............................................................................................................................................7
3.1.2. Constructor......................................................................................................................................................................7
3.1.3. Pre-Defined Constants................................................................................................................................................7
3.2. Using LEDs.......................................................................................................................................................................................7
3.3. Using EEPROM................................................................................................................................................................................8
3.4. Reading Serial ID...........................................................................................................................................................................8
3.5. Converting types...........................................................................................................................................................................8
4. Input/Output pins............................................................................................................................... 10
4.1. Reading ANALOG inputs ........................................................................................................................................................ 11
4.2. Digital I/O ..................................................................................................................................................................................... 11
4.2.1. Setting DIGITAL pin mode ......................................................................................................................................11
4.2.2. Reading DIGITAL Inputs ...........................................................................................................................................11
4.2.3. Writing DIGITAL Outputs .........................................................................................................................................11
4.2.4. DIGITAL1 pin as PWM output .................................................................................................................................12
v4.0
-3-
v4.0
Introduction
1. Introduction
Waspmote provides some libraries to manage USB interaction and other general tasks (blinking LEDs, some string conversions,
etc).
To manage these tasks, some functions have been developed and two libraries have been created: USB Library and Utils Library.
2. USB Library
2.1. Waspmote Libraries
2.1.1. Waspmote USB Files
WaspUSB.h ; WaspUSB.cpp
2.1.2. Constructor
To start using Waspmote USB library, an object from class WaspUSB must be created. This object, called USB, is created inside
the Waspmote USB library and it is public to all libraries. It is used through the guide to show how the Waspmote USB library
works.
When creating this constructor, one variable is initialized. This variable specifies the number of the UART that USB is going to
use (UART0 in this case).
2.2. Initialization
Two functions have been created to open and close the UART used to communicate via USB.
Example of use
{
USB.ON(); // Opens the UART at 115200 bps by default
USB.OFF(); // Closes the UART
}
-4-
v4.0
USB Library
Print a string
{
char* string=Hello;
USB.print(string); // Writes a string to the UART
USB.println(string); // Writes a string to the UART adding an EOL
}
-5-
v4.0
USB Library
Print numbers in different formats
{
USB.println(78);
USB.println(78, BIN);
USB.println(78, OCT);
USB.println(78, DEC);
USB.println(78, HEX);
//
//
//
//
//
Writes
Writes
Writes
Writes
Writes
78
78
78
78
78
in
in
in
in
in
integer format: 78
binary format: 1001110
octal format: 116
integer format: 78
hexadecimal format: 4E
http://www.libelium.com/development/waspmote/examples/usb-01-usb-functions
http://www.libelium.com/development/waspmote/examples/usb-02-usb-printf-function
-6-
v4.0
Utilities Library
3. Utilities Library
3.1. Waspmote Libraries
3.1.1. Waspmote Utilities Files
WaspUtils.h ; WaspUtils.cpp
3.1.2. Constructor
To start using the Waspmote Utilities library, an object from class WaspUtils must be created. This object, called Utils, is created
inside the Waspmote Utilities library and it is public to all libraries. It is used through the guide to show how the Waspmote
Utilities library works.
When creating this constructor, no variables are initialized.
http://www.libelium.com/development/waspmote/examples/ut-02-using-leds
-7-
v4.0
Utilities Library
AVAILABLE
1023 1024
4095
The function that writes the EEPROM is Utils.writeEEPROM. This function does not permit to write reserved EEPROM
addresses.
Example of use
{
Utils.writeEEPROM(1024,B); // Write the value B in the address 1024
uint8_t data=Utils.readEEPROM(1024); // Reads the value stored in the address 1024
}
-8-
v4.0
Utilities Library
C standard Library allows the user to convert between different variable types. This is a list with some supported function
prototypes:
Convert string to int (2 Bytes):
{
int number = atoi(2341);
}
http://www.libelium.com/development/waspmote/examples/ut-04-convert-types
-9-
v4.0
Input/Output pins
4. Input/Output pins
Waspmote can communicate with other external devices using different input/output ports.
ANALOG
DIGITAL 8
GND
DIGITAL 6
DIGITAL 7
DIGITAL 4
DIGITAL 5
DIGITAL 2
DIGITAL 3
RESERVED
DIGITAL 1
ANALOG 6
ANALOG 7
ANALOG 4
ANALOG 5
ANALOG 2
ANALOG 3
ANALOG 1
GPS POWER
5V SENSOR POWER
SDA
SCL
GND
GND
ANALOG 6
ANALOG 7
3V3 SENSOR
3V3 SENSOR
-10-
v4.0
Input/Output pins
val1
val2
val3
val4
val5
val6
val7
=
=
=
=
=
=
=
analogRead(ANALOG1);
analogRead(ANALOG2);
analogRead(ANALOG3);
analogRead(ANALOG4);
analogRead(ANALOG5);
analogRead(ANALOG6);
analogRead(ANALOG7);
//
//
//
//
//
//
//
Read
Read
Read
Read
Read
Read
Read
the
the
the
the
the
the
the
input
input
input
input
input
input
input
ANALOG1
ANALOG2
ANALOG3
ANALOG4
ANALOG5
ANALOG6
ANALOG7
and
and
and
and
and
and
and
store
store
store
store
store
store
store
its
its
its
its
its
its
its
value
value
value
value
value
value
value
in
in
in
in
in
in
in
val1
val2
val3
val4
val5
val6
val7
-11-
v4.0
Input/Output pins
-12-
v4.0
.bss
Variables
Heap
Free Memory
Stack
http://www.libelium.com/development/waspmote/examples/ut-05-get-free-memory
-13-
v4.0
Pin3: GND
Example of use:
{
float temperature;
temperature = Utils.readTemperature();
}
Figure 6: MCP9700A Temperature sensor
http://www.libelium.com/development/waspmote/examples/bs-01-reading-temperature
-14-
v4.0
Figure 7: LDR sensor
Example of use:
{
int light;
light = Utils.readLight();
}
http://www.libelium.com/development/waspmote/examples/bs-02-reading-light
6.3. Humidity
The humidity sensor 808H5V6 can be plugged directly to the secondary I/O Sensor socket. The sensor pins are described below
indicating where they have to be plugged to:
Pin3: GND
Example of use:
{
int humidity;
humidity = Utils.readHumidity();
}
http://www.libelium.com/development/waspmote/examples/bs-03-reading-humidity
http://www.libelium.com/development/waspmote/examples/bs-04-reading-sensors
-15-
v4.0
http://www.libelium.com/development/waspmote/examples/bs-05-reading-ds18b20
-16-
v4.0
http://www.libelium.com/development/waspmote/examples
-17-
v4.0
API changelog
8. API changelog
Function / File
Changelog
Version
MAX_ARGS
V0.31 v1.0
MAX_ARG_LENGTH
V0.31 v1.0
EEPROM_START
V0.31 v1.0
SD_SELECT
V0.31 v1.0
SRAM_SELECT
V0.31 v1.0
SOCKET0_SELECT
V0.31 v1.0
SOCKET1_SELECT
V0.31 v1.0
ALL_DESELECTED
V0.31 v1.0
char arguments[MAX_ARGS][MAX_ARG_LENGTH];
V0.31 v1.0
WaspUtils::setMuxGPRS
V0.31 v1.0
WaspUtils::setMuxUSB
V0.31 v1.0
WaspUtils::muxOFF
V0.31 v1.0
WaspUtils::setMuxSocket0
V0.31 v1.0
WaspUtils::parse_decimal
Function deleted
V0.31 v1.0
WaspUtils::parse_degrees
Function deleted
V0.31 v1.0
WaspUtils::gpsatol
Function deleted
V0.31 v1.0
WaspUtils::gpsisdigit
Function deleted
V0.31 v1.0
WaspUtils::parse_latitude
Function deleted
V0.31 v1.0
WaspUtils::Dec2hex
Function deleted
V0.31 v1.0
WaspUtils::array2long
Function deleted
V0.31 v1.0
WaspUtils::setID
V0.31 v1.0
WaspUtils::setAuthKey
V0.31 v1.0
WaspUtils::readSerialID
V0.31 v1.0
WaspUtils::readTempDS1820
V0.31 v1.0
WaspUtils::readTemperature
V0.31 v1.0
WaspUtils::readHumidity
V0.31 v1.0
WaspUtils::readLight
V0.31 v1.0
WaspUtils::strtolong
Function deleted
V0.31 v1.0
WaspUtils::sizeOf
Function deleted
V0.31 v1.0
WaspUtils::strCmp
Function deleted
V0.31 v1.0
WaspUtils::strCp
Function deleted
V0.31 v1.0
WaspUtils::setSPISlave
V0.31 v1.0
-18-
v4.0