Category: Spark Core

Interactive Voice Response system using Particle Core, GSM Breakout Board, Emic2 and DTMF Decoder

Source Code

My previous project using was a Voice Messaging system based on Particle Core, GSM Breakout Board and Emic2 TTS Module. Actually this was the project I first started but because of the unavailability of the DTMF Breakout Board, I released the Voice Messaging project.

Overview

This project is an IVR System. Following hardware components are using for this project.

  1. Particle Core as main processor and for Internet connectivity
  2. A GSM Breakout Board for Cellular connectivity
  3. SparkFun I2C/SPI-to-UART Breakout Board for SPI to UART
  4. Emic2 Text to Speech module for TTS
  5. DTMF Breakout Board

Here is the overview of the different hardware components and how they interact.

enter image description here

This project is almost similar to my previous Voice Messaging project except it has an additional DTMF Breakout Board. This is used to decode the DTMF signals. This board is used to detect which number user has pressed on other end. The Audio Out of the GSM Breakout Board is connected to the Audio Input of the DTMF Decoder and the pins DR, D0, D1, D2 and D3 are connected to Particle Core pins D2, D3, D4, D5 and D6 respectively. The Data Ready (DR) pin of the DTMF Board will be high when the boards detects the DTMF tone and it is decoded correctly. When this pin is high, we read the data pins D0…D3, this will be give us the number pressed on the other end of the telephone line.

In this sample the GSM Board is configured to answer the incoming call after 2 rings, so when a call is received it will be automatically answer after 2 rings. When the call is answered, application will speak out a welcome message and prompts the user to enter a 4 digit PIN. The default PIN is 9999, but you can change it whatever you like. When the correct PIN is entered, the application will ask you to enter 7, 8 or 9. Pressing 7 will speak out the current temperature, pressing 8 will speak out current humidity and pressing 9 will hang up the call. The sample use DHT Sensor to read temperature and humidity. This sensor is connected to the pin D0 of Particle Core.

Wiring

Particle Core and I2C/SPI-to-UART

  • Core MOSI to I2C/SPI-to-UART MOSI
  • Core MISO to I2C/SPI-to-UART MISO
  • Core SCK to I2C/SPI-to-UART SCK
  • Core SS to I2C/SPI-to-UART SS

I2C/SPI-to-UART and GSM Shield

  • I2C/SPI-to-UART Vcc to 3.3v
  • I2C/SPI-to-UART GND to GND
  • I2C/SPI-to-UART Tx to GSM Board Rx
  • I2C/SPI-to-UART Rx to GSM Board Tx
  • GSM Board 5v to 5v
  • GSM Board GND to GND

Particle Core and Emic2 TTS Module

  • Core Tx to Emic2 Rx
  • Core Rx to Emic2 Tx
  • Emic2 5v to 5v
  • Emic2 GND to GND

DTMF Board and GSM Breakout Board

  • DTMF Board Audio In to GSM Board Audio Out

DTMF Board to Particle Core

  • DTMF Board 5v to 5v
  • DTMF GND to GND
  • DTMF DR to Particle Core D2
  • DTMF D0 to Particle Core D3
  • DTMF D1 to Particle Core D4
  • DTMF D2 to Particle Core D5
  • DTMF D3 to Particle Core D6

Screenshots

enter image description here

Demo Video

https://www.youtube.com/watch?v=sPZ4FBCrNjo

Send Voice Message using Particle and GSM Breakout Board

Source Code

I bought a GSM Breakout Board and it was resting on my table for a long time. Last week I decided to work on a project using GSM and Particle Core. Actually I decided to work on 2 project, one is to deliver a voice message to a specified number and other one is an IVR system. Here is the first project I worked, send voice message to a specified telephone number. I am working on second one and will post here once completed.

Overview

This project basically call a number, when the call is picked up on the other end, deliver a voice message and then hangup. This project mainly uses 4 Hardware Components.

  1. Particle Core as main processor and for Internet connectivity.
  2. A GSM Breakout Board for Cellular connectivity.
  3. SparkFun I2C/SPI-to-UART Breakout Board for SPI to UART.
  4. Emic2 Text to Speech module for TTS.

enter image description here

Since both GSM Board and Emic2 are Serial based, you need 2 Serial to communicate to these two. So first I tried Serial1 and Serial2 on Spark Core. But only one was working at a time, either Serial1 or Serial2. I was not able to get both working at the same time. So I used SPI to Serial Breakout Board. This breakout board convert SPI or I2C to Serial. The Emic2 is connected through Serial2 and GSM Board is connected through the SPI to Serial board.

Adafruit FONA library is used to communicate to the GSM Board. Even though this is written for Adafruit FONA Breakout Board, it will work with other SIM800/SIM900 boards. FONA is based on SIM800L module. I have slightly modified the Adafruit FONA Library to include the functions to read current call status and set the auto answer.

For voice output I am using Emic2 Text to Speech module. The audio output of this module is connected to the Audio Input of the GSM Breakout Board using 3.5mm Audio connector.

The Particle Core application exposes three functions, one to set the number to which voice message has to be delivered, second one to set the message and third to set the number of rings before automatically answer the call. When we send voice message, the application place a call to the number and waits for the other end to pick up the phone. Once the phone is picked up, voice message is delivered and the application hang up. The status of the current call is obtained using the GSM900 AT Command AT+CLCC. This command returns the status of the current call. This command is explained in this document. The response string contains the status of the current call if any, if there is no active call the command returns just the string “OK”. Third field of the response string contains the status of the current call. Following are the possible values of this field.

  1. 0 Active
  2. 1 Held
  3. 2 Dialing
  4. 3 Alerting
  5. 4 Incoming
  6. 5 Waiting

Once the call is placed, the application waits for the active call status to become active and the message is delivered using the Emic2 TTS Module and hangs up the call once the TTS is completed. For incoming call if the auto answer is set, the SIM module automatically answer the call after the specified number of rings. In this case also when the call is active, the application delivers the message and hangs up.

Wiring

Particle Core and I2C/SPI-to-UART

  • Core MOSI to I2C/SPI-to-UART MOSI
  • Core MISO to I2C/SPI-to-UART MISO
  • Core SCK to I2C/SPI-to-UART SCK
  • Core SS to I2C/SPI-to-UART SS

I2C/SPI-to-UART and GSM Shield

  • I2C/SPI-to-UART Vcc to 3.3v
  • I2C/SPI-to-UART GND to GND
  • I2C/SPI-to-UART Tx to GSM Board Rx
  • I2C/SPI-to-UART Rx to GSM Board Tx
  • GSM Board 5v to 5v
  • GSM Board GND to GND

Particle Core and Emic2 TTS Module

  • Core Tx to Emic2 Rx
  • Core Rx to Emic2 Tx
  • Emic2 5v to 5v
  • Emic2 GND to GND

Screenshots

Circuit

Web Interface

Demo Video

https://www.youtube.com/watch?v=dfa3WrB7OzY&feature=youtu.be

Spark Core and Temboo Light Monitor

https://github.com/krvarma/SparkCore_Temboo

Here is a project I worked on last weekend using Spark Core and Temboo. Temboo provides easy and fast access to different APIs. It provides different libraries to connect to Temboo services and access it. There is a great Spark Core port of Temboo Arduino library which I decided to use for this project.

This project uses a low cost Light Sensor to constantly monitor the light level. If it is below a particular level then call a Temboo Choreo. For this project I am using Nexmo library (Library\Nexmo\Voice\CaptureTextToSpeechPrompt) to call a particular phone number, speaks out a message and get input (digits). Temboo library provides a easy way to call any Choreo and get the return value. The return value may vary based on the Choreo we are using. It can XML or JSON. In this project I am using JSON return string.

As everybody knows parsing JSON/XML from a memory limited MCU is not that easy. For this reason Temboo library provides Output Filters to make it very easy to process the return values. The above link provides a detailed documentation on how to use Output Filters. The Nexmo’s return value in JSON format contains an element ‘digits’ which contains the user entered digit. In this sample if the digit is ‘1’ then the LED attached to D2 is turn on. When the light level goes above the limit the LED is turned off. Instead of LED we can connect anything more meaningful like a Relay control to turn on the light, etc…

Using the project

To use this project, you should configure the Temboo Nexmo library and save it to a profile (https://www.temboo.com/library/Library/Nexmo/Voice/CaptureTextToSpeechPrompt/). You should also have one Nexmo account either trial/paid. Replace the following #defines of temboo-light.ino with actual Temboo credentials.

// Your Temboo account name 
#define TEMBOO_ACCOUNT "<<temboo account>>"  
// Your Temboo app key name
#define TEMBOO_APP_KEY_NAME "<<temboo app key name>>"  
// Your Temboo app key
#define TEMBOO_APP_KEY "<<temboo app key>>"  

Replace the Temboo profile name (which is saved previously) at line no. 111 of temboo-light.ino

Also you have Replace the Spark Core credentials in the temboo.html page.

Screenshots

enter image description here

enter image description here

enter image description here

Demo Video

https://www.youtube.com/watch?v=BORNp10bbY0

XBee and Spark Core, Part 3 – Analog Input using Light Sensor

https://github.com/krvarma/XBee_SparkCore_LightSensor

Here is the part 3 of my XBee and Spark Core series. This part is about Analog Input using a Light Sensor. In this part AD1 of the Remote XBee is configured as Analog Input. AD1 is connected to Light Senor. As usual this XBee is configured as Router AT and Coordinator is connected to Spark Core via Serial. The Remote XBee is configured to send samples every 1 second and the Spark Core receives this IO Sample data and reads the Light Sensor value.

Same as the previous project, I am using the XBee library and reads the analog data using getAnalog method of the ZBRxIoSampleResponse class.

To monitor the values, in this part I created a Freeboard.io data source and configured a Display Panel.

Screenshots

enter image description here

enter image description here

enter image description here

XBee and Spark Core, Part #2 – Remote Door Monitor using XBee Digital Input

https://github.com/krvarma/Spark_XBee_Remote_Door_Monitor

This is the part 2 of my XBee and Spark Core series. In this part I worked on a simple remote door monitor using XBee, Spark Core and a Magnetic Contact Switch (Door Sensor).

In this project, the remote XBee is configured as Router AT. The DIO4 of the XBee is setup for Digital Input (3) and it is also configured to send IO Sample data every 1 second (setting IR to 3E8 hex). The Magnetic Contact Switch is connected to DIO4 of this XBee, so when the door is closed the DIO4 will be HIGH and when the door is open the DIO4 will be LOW.

A Coordinator XBee is connected to Spark Core using Serial. The Coordinator receives the IO Sample data that Remote XBee is sending and parse it to see whether DIO4 is HIGH/LOW. An event is generated based on the door state.

The companion web page listens for the above event and display some graphics based on the whether the door is open or closed.

I am using XBee Library ported by @peekay123. The Spark Core continuously reads XBee packets and look for packets with API ID ZB_IO_SAMPLE_RESPONSE. This is the API ID of the IO Sample Data. If it is IO Sample data, then read the data into ZBRxIoSampleResponse class. The ZBRxIoSampleResponse.isDigitalOn() method can be used to find whether a particular PIN is ON/OFF.

Screehshots

Spark Core and Coordinator XBee

Remote XBee and Door Sensor

Web Page

Demo Video

Demo Video

Using Spark Core and XBee for RF Communication, Part #1

https://github.com/krvarma/XBee_SparkCore

Here is one of the project I worked these days, this is a part one that uses Spark Core and XBee for RF Communication. My intention is to use XBee(s) and Spark Core to create very simple Home Automation project. In this part, I just turn on/off a remote LED which can be controlled using a Web Application.

The project is to control a remote light, i.e. turn on/off the light. In this part I am using Spark Core and two XBee’s (either Series 1 or Series 2). If you are using Series 1, then one should be configured to accept API Command, other can be wither API or AT mode. If you are using Series 2, then one should be configured as coordinator API and other can either be a Router AT/API or an End Device.

Introduction

Here in this project the Coordinator API XBee is connected to Spark Core and communicate using Serial. Spark Core is used as Internet Gateway to control XBee. The Core application uses XBee Library ported by @pkourany. For this project I am using XBee Remote AT command to control remote XBee(s). For more about API Mode and Remote AT Commands please refer to this link.

The Router XBee’s D0, D1, D2 and D3 pin are connected to four LEDs which can be remotely turn on/off. Any device can be connected to any pins and send the Remote AT commands to the remote XBee. It can a Rely connected to Electrical Light, or anything else.

To send Remote AT Command, you can either use a Broadcast address or a destination 64-bit (MAC/EUI64) address of the XBee module. Using the 64-bit destination address allows us to send commands to a particular XBee. There is also a 16-bit configurable address which can be used to group multiple XBees and send commands to that group. Since this is a different topic and is not in our scope, for more information refer to the Digi documentation.

The sample JavaScript Web application is used to control the remote light. To use this application you should replace the deviceid and accesstoken with actual values. When the application is opened you will be asked to enter the Name (any name, just for display purpose) and the 64-bit remote address of the XBee that is connected to the Relay Module. Once it is entered you can turn on/off the D0, D1, D2 and D3 pins.

Here you can find a very useful API Frame Generator from Digi International. This is extremely useful for the development and debugging, I used it a lot for this project.

Wiring

Coordinator XBee and Spark Core

  • XBee Vcc to Spark Core 3V3
  • XBee GND to Spark Core GND
  • XBee DOUT to Spark Core Rx
  • XBee DIN to Spark Core Tx

Router XBee and Relay Module

  • XBee Vcc to 3v3
  • XBee GND to GND
  • XBee DIO0 to LED1
  • XBee DIO1 to LED2
  • XBee DIO2 to LED3
  • XBee DIO3 to LED3

Screenshots

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Demo Video

https://www.youtube.com/watch?v=n_4AgTekWqs

Spark Core and SmartThings

https://github.com/krvarma/SmartThings_SparkCore_Sensor

This is a sample application using Spark Core and SmartThings.

The Spark Core application uses DHT22 Sensor for Temperature and Humidity value and defines two Spark.function to read these sensor values.

The SmartThings application defines a new Device Type and uses Spark Core APIs to read the sensor values. The device type specifies the “Polling” capability but only sometimes it is working (Raised the issue and I am awaiting SmartThings reply on this)

Wiring

  1. DHT 3.3v to 3.3v
  2. DHT GND to GND
  3. DHT SIG to D4

Installation

  1. Create a new device type (https://graph.api.smartthings.com/ide/devices) with Name: Spark Core Temperature Sensor, Author: Krishnaraj Varma, Capabilities: Polling Relative Humidity Measurement Sensor Temperature Measurement
  2. Create a new device (https://graph.api.smartthings.com/device/list) with Name: Your Choice, Device Network Id: Your Choicem Type: Spark Core Temperature Sensor (should be the last option), Location: Choose the correct location, Hub/Group: Leave blank
  3. Update device preferences, Click on the new device to see the details. Click the edit button next to Preferences and Enter the Device ID and Access Token
  4. Open the Mobile Application and add the newly created device, click refresh to see the Temperature and Humidity values

Screenshots

enter image description here

enter image description here

Reference and Inspiration

https://gist.github.com/Dianoga/6055918

Spark Core and TinyGPS Library

https://github.com/krvarma/TinyGPS_SparkCore

Here comes a sample application using Spark Core and TinyGPS library. TinyGPS is a very powerful and fast NMEA GPS parser for Arduino and compatible. In this sample I am using on some basic features to read the geo-coordinates from a MediaTek MT3329 GPS receiver.

The sample publishes the GPS location every 15 minutes. There is also an HMTL page that uses Google Map API to display Spark Core location on a Map. To use this sketch you should replace the tag deviceid and accesstoken with actual values.

Wiring

  1. GPS Vcc to 3.3V
  2. GPS GND to GND
  3. GPS Tx to Rx
  4. GPS Rx to Tx

Screenshot

enter image description here

enter image description here

Happy GPS coding 🙂

Spark Core and Plotly

https://github.com/krvarma/Plotly_SparkCore

Here is a sample application to stream data to Plotly using Spark Core. The application stream temperature value from DHT22 Sensor to Plotly. To use this application create a Plotly account, download the source and open it in Spark Editor and replace the tokens streamtoken, username, apikey and filename with corresponding values from Plotly settings.

This application uses Plotly SDK form GitHub. I took the plotly_streaming_wifi source and ported to Spark Core. It is only a simple and straightforward port, only two modification done. 1. Copy the method dtostrf form this location and included in Plotly class and 2. commented the method void print_(const __FlashStringHelper*d) because this method was causing some compiler errors (I didn’t dig deep into it, just commented the method).

Screenshots

spark core wiring

enter image description here