-
Notifications
You must be signed in to change notification settings - Fork 0
Setting up analog sensors and flashing the XDK110
On this page you can learn how to extend the Bosch XDK110 to use analog sensors and how to send this data to the tangle using Keepy.
The Bosch XDK is a nifty device that packs a bunch of sensors into a small package and make it easy to start prototyping. It comes with an extension bus that allows you to connect a breadboard and add more sensors.
- 1x XDK 110
- 1x Soil Sensor
- Jumper Wires
I wasn't able to find any Fritzing components for the XDK Extension Bus. So I added an Arduino to show how to wire the sensor. Instead of connecting to the A0 on the Arduino, you should connect it to an ADC pin on the Extension Bus for example the PD5 pin.
Start by setting up the XDK Workbench in order to work with the device.
If you cloned my project you should have a folder named "XDK110_IotaPlantSensor"
The first thing to do is go to the source folder and open the IotaPlants.h file. Here you have to edit the definitions to connect to your own wifi and give the XDK110 a device name and finally point it to your Keepy installation, you can also choose to use the original Keepy project from iot2tangle, but then you won't have the visualizations! :)
Now you should be able to flash the xdk, by building the project and clicking the flash button.
But we want to extend it.
To be able to gather data from analog sensors we need to use the Analog to Digital Converter (ADC).
The XDK110 has two ADC pins (PD5 and PD6) so you have to use one of those. Check this link for more technical information on the XDK110.
In my case I have added an analog moisture sensor, so what we want to do here is measure the resistance. Because it has a proportional value to the moisture in the soil! You can read more about how the sensor works here
We need to add two files in the sensors folder. First External.c.
It has an init function where I configure the ADC pin (PD5) as an input with a pull-down resistor.
It also has the function processExternalData that does the bulk of the work and reports the value back when called. You can read more about how the ADC works on the XDK 110 here.
The second file we have to add is a header file External.h to the protected folder, to be able to import it.
Now that we have our new sensor functionality created, we need to use it in the IotaPlants.C file!
First add the include to our header file:
#include "External.h"
Then add an entry to the typesSensors array in the beginning of the file:
bool typesSensors[8] = {
true, //ENVIRONMENTAL
true, //ACCELEROMETER
true, //GYROSCOPE
true, //INERTIAL
true, //LIGHT
true, //MAGNETOMETER
true, //ACOUSTIC
true, //EXTERNAL
};
As you can see I have already added the External data point, but if you want to add multiple sensors you have to create one for each datapoint you add.
This is also where you can disable the sensors that are already working out of the box on the XDK110.
Next find the appInitSystem function and add a case for our init function for our new sensor:
int i=0;
for(i=0;i<MAX_SENSORS_ARRAY;i++){
if(typesSensors[i]){
switch(i)
{
case ENVIRONMENTAL:
environmentalSensorInit();
break;
case ACCELEROMETER:
accelerometerSensorInit();
break;
case GYROSCOPE:
gyroscopeSensorInit();
break;
case INERTIAL:
inertialSensorInit();
break;
case LIGHT:
lightsensorInit();
break;
case MAGNETOMETER:
magnetometerSensorInit();
break;
case ACOUSTIC:
acousticSensorInit();
break;
case EXTERNAL:
externalSensorInit();
break;
}
}
}
Last thing in the IotaPlants.C file is that we have to add code to actually get the reading, this is in the switch inside the receiveBufferFromSensors function:
switch(i)
{
case ENVIRONMENTAL:
aux = processEnvSensorData(null,0);
break;
case ACCELEROMETER:
aux = processAccelData(null,0);
break;
case GYROSCOPE:
aux = processGyroData(null,0);
break;
case INERTIAL:
aux = processInertiaSensor(null,0);
break;
case LIGHT:
aux = processLightSensorData(null,0);
break;
case MAGNETOMETER:
aux = processMagnetometerData(null,0);
break;
case ACOUSTIC:
aux = processAcousticData(null,0);
break;
case EXTERNAL:
aux = processExternalData(null,0);
break;
}
The final thing to be able to build the project is that we must expand the Makefile to include the BSP_BoardShared.h interface. We must also add the External.c as seen below.
#List all the application header file under variable BCDS_XDK_INCLUDES in a similar pattern as below
export BCDS_XDK_INCLUDES = \
-I$(BCDS_APP_SOURCE_DIR_SENSORS)/protected \
-I$(BCDS_BASE_DIR)/xdk110/Platform/BSP/source \
export BCDS_XDK_APP_SOURCE_FILES = \
$(BCDS_APP_SOURCE_DIR)/Main.c \
$(BCDS_APP_SOURCE_DIR)/IotaPlants.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/EnvironmentalSensor.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/Accelerometer.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/Gyroscope.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/InertialSensor.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/LightSensor.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/Magnetometer.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/Acoustic.c \
$(BCDS_APP_SOURCE_DIR_SENSORS)/External.c \
Now you should be ready to build and flash the XDK and you should start seeing data come into Keepy, if you have set that part up, if you haven't click below to do it!
Learn to set up an ESP32 to listen to these values we have just setup and control a relay!