Wednesday, December 5, 2018

LTE Cellular Shield for Arduino

Ever wanted to turn your Arduino into a phone with LTE technology? Sure, there are lots of 2G and 3G modules out there, but of the few that exist, not many LTE modules for Arduino are well-documented or are insanely expensive! With the SIM7500 shield that's about to change! This shield not only has standard LTE technology with worldwide coverage but it also supports 3G, GPS positioning for asset tracking, and I've also thrown in an I2C temperature sensor in there as well, convenient for at least sending some data to the cloud. You're also not stuck with using 5V Arduino; the shield allows you to configure your own logic voltage so you can interface this with Raspberry Pi and other 3.3V microcontrollers.
Hardware components
Arduino UNO 
Botletics SIM7500 Shield Kit
Hologram Global IoT SIM Card
USB-A to Micro-USB Cable

As a firm believer in great documentation I've set out on a journey to use just about every cellular module I can get my hands on, including theSIM7000module, this SIM7500 project, and hopefully others as well! Join me in this adventure, share your comments, and let's get Arduino users all around the world connected to the cell towers!

The SIM7500 Shield
So what exactly is this project about? Basically it's a "shield" that plugs into an Arduino Uno, Mega, Leonardo, etc. and gives it LTE cellular connectivity, kind of like a phone. You can send and receive text messages, utilize LTE data to send or receive sensor data, use the GPS to track location, call another device just as you would on your phone, and all sorts of other functions that I'm still documenting and unlocking. Below is a quick overview diagram showing the various features of the shield:
Beastly features in a compact shield form factor!


Compatible with Arduino Uno, Arduino Mega, and Arduino Leonardo or practically any 1.8-5V microcontroller if wired externally and set properly (see the shield pinouts in this tutorial)
LTE CAT-1 supporting uplink speed up to 5Mbps, downlink up to 10Mbps
The shield comes in two versions, SIM7500A and SIM7500E (learn how to select a version). Both support 4G LTE, 3G but the SIM7500E also supports 2G and 2.5G fallback
Supports text messaging, voice calling and microphone input
Supports TCP/IP/IPV4/V6 Multi-PDP, MT PDP and FTP/FTPS/HTTP/HTTPS/SMTP/POP3/DNS/MMS
Integrated GNSS/GPS positioning capabilities
MCP9808 High-accuracy I2C temperature sensor with 0.25° typical accuracy
Micro USB for debugging and sending AT commands
SIM7500 module power and network status LEDs
Convenient u.FL antenna connectors for added flexibility
So, first things first: in order to use this module we need to decide which version is most appropriate since the SIM7500 comes in two versions, the SIM7500A and the SIM7500E (probably more versions coming soon). The main differences are the geographical regions in which they operate due to the supported LTE "bands". For more info, please see this Github wiki page on how to select the appropriate version. As you can see, both versions support 3G but the SIM7500E also supports 2.5G and 2G fallback.

Now let's explain some of the features. One cool thing about this shield is that it has both voice input (via an electret microphone) and audio put (speaker) support, unlike my other SIM7000 shield which used the low-bandwidth LTE CAT-M and NB-IoT technologies and voice isn't really feasible or top-notch even if it were done. That means you can call your friend with your Arduino... how cool is that?

Perhaps the most important feature (and probably why you want this shield) is it's LTE data capabilities. Want to make a DIY home security device that takes a picture and sends it to a server? No problem! With this shield you can enable data, do HTTP/HTTPS requests, FTP stuff, and many other cool things that I have yet to explore with you all!

On the software side things are really easy! Just follow these instructions to install the Arduino library (which is an improved version of the Adafruit FONA library) and run the examples!

Goals for This Project
My goal for this project is to share what I've done in creating a powerful shield for Arduino users to cellular-ize (I'll say this with pride) their projects using LTE technology. I'm on a quest to document the latest and greatest cellular modems and make them easy to interface with Arduino and other ubiquitous platforms while providing full documentation!

Keep hacking!

How to make an kitchen timers

This project is made by Angelo Fiorillo.
In the beginning God created the heaven and the earth. And human beings. And human beings created digital kitchen timers, like this one.
And human beings said, Cool but a little dismal. Let's make a better one!

And God said, I heard your call, let there be Arduinos: and there was Arduinos all over the earth, and that was good.

And human beings took an Arduino and created a better kitchen timer, like this one


And God saw the new kitchen timer and said: I saw your new kitchen timer and it looks awful, but it seems too much fun! And that is good. :-)

What you need to have
Now that you know where all this came from, let's go deep into it.

All components I used came from the Arduino Starter Kit, including the small breadboard you see in the pics and in the video. Feel free to accomodate the project into a larger one, if you wish.

You'll need a power source too: while playing around, the PC' USB port and cable will be enough.
Hardware components
Arduino UNO
Adafruit Standard LCD - 16x2 White on Blue
SparkFun Pushbutton switch 12mm
Resistor 10k ohm
Single Turn Potentiometer- 100k ohms
Resistor 221 ohm
Buzzer
Breadboard (generic)

What you need to do
First: please gather all needed components from the Starter Kit or your preferred component bin; if you don't have one, don't panic. There's plenty of on the Internet. You can find the component list below.

And, well, you'll need the code too. It's in its box, below again.

How it works
Basically, like any other similar device you can buy for a buck at any store near you. But this is yours. And this will show you how those little gadgets actually work.

The keyword here is: current mode. The timer itself can run in only one out of four modes at a time:

IDLE - the timer is awaiting for your input, showing the currently set time amount; this is also the initial mode after power up or reset.
SETUP - you can enter this mode by long-pressing S4 (in the code this is called also "reset button"); here, by using S3 ("start stop button"), you can choose which value to change in order to set the elapsed time to be counted down later; finally, using S2 ("down button") and S1 ("up button") respectively, you can decrease or increase the choosen value (hours, minutes or seconds).
RUNNING - You can enter this mode by pressing S3, while leaving it will require both S3 or S4 (which will lead you to IDLE mode).
RINGING - When the desider amount of time is elapsed, this mode is automatically activated; you can leave it (i.e., make the little boy stop ringing) by pressing any switch.
The code
First, we need to include the proper libraries:
#include <LiquidCrystal.h>
#include <TimeLib.h>

If you don't have them already, you'll need to download and install them:

Paul Stoffregen's Time Library
Arduino LiquidCrystal Library
Next, let's initialize that nice LCD module:
Please feel free to scramble the pins at your will in order to obtain a nice wiring layout: don't follow me in this, as I did a terrible wiring plan! :D For instance, you can reverse the latter four pins in the above statement in order to avoid the yellow wires crossing you can see in the schematic below (obviously, you'll have to adjust the button pin constants accordingly, see below). Play, have fun! The life with Arduinos starts right after that copy/paste!

The next 51 code lines contain the static variables declaration and initialization. Please feel free to browse them, their crystal-clear names and some scattered comments will guide you understanding the whole thing.

The setup() function carries out the usual preliminary steps you've seen gazillions of times in any Arduino sketch out there and so far. The only notable statement is the first, which will set the initial LCD display cursor's position. Because, yes: this module requires you to setup a position along its rows and cols and then to "print" something, which will appear starting from that position.

Now let's move to the loop() function.

First of all, let's discover the switch statuses. In order to achieve this, the following code block is used for nearly each of them:

  /*
   * Start/Stop button management
   */
  startStopButtonPressed = false;
  startStopButtonState = digitalRead(startStopButtonPin);
  if(startStopButtonState != startStopButtonPrevState)
  {
    startStopButtonPressed = startStopButtonState == HIGH;
    startStopButtonPrevState = startStopButtonState;
  }

A digitalRead is issued against the related pin and the result is compared to a previously readed value: if something has changed, the new value is stored for future reference and the bool "xxxButtonPressed" static variable is set to true if the button is pressed.

Looking at the circuit diagram below, you'll notice that each input pin is forced to LOW by a 10k resistor unless the corresponding switch is pressed and the pin itself is directly connected to +5V. A fairly classic scenario, uh?

Previously, I said "nearly each of them" because there's one button that acts in a different way than the others: S4. Its code block is capable of detecting the aforementioned long press in order to enter SETUP mode.

Next comes the mode management block switch: each case looks at the button state triggers ("xxxButtonPressed") and redirects the flow toward the proper new state, or performs the proper action.
case MODE_IDLE:
      if(resetButtonPressed)
      {
        Reset();
      }
      if(resetButtonLongPressed)
      {
        currentMode = MODE_SETUP;
      }
      if(startStopButtonPressed)
      {
        currentMode = currentMode == MODE_IDLE ? MODE_RUNNING : MODE_IDLE;
        if(currentMode == MODE_RUNNING)
        {
          // STARTING TIMER!
          startTime = now();
        }
      }
      break;
The previous code snippet shows how the IDLE mode is managed, and it's pretty self-explanatory. Another example shows how any button press while ringing will stop it:
case MODE_RINGING:
      if(resetButtonPressed || startStopButtonPressed || downButtonPressed || upButtonPressed)
      {
        currentMode = MODE_IDLE;
      }
      break;

Looks easy, isn't it? :-) It is.

The next block - "Time management" - performs the actual time difference calculation, triggers the RINGING mode and actually rings the buzz when it's time to do so.

The last block - "LCD management" - manages the LCD display for each mode by printing the proper strings at their proper locations.

That's it.

Wrap up and action!
Now that this little puppy has no more secrets to you, let's see it in action. Thanks for watching, and have fun!