Sim 800

//Rough Draft but I am posting anyway. Need to add pics and links 🙂

So I have been experimenting with the SIM800 module. I got the coreboard from Aliexpress for $5 and what I got was this…<insert pic>

My first attempt to power it from the arduino VCC to 5v and GND to GND failed. I was surprised. The module had spoilt? Google to the rescue. It turns out, I was to blame. I didn’t read the datasheet. The VCC require is 3.6v to 4.4v with 4v being recommended. I connected it to 5V. Yikes! Got to say thumbs up to the engineers that my module didn’t immediately emit the magic smoke. It also turns out, that I didnt consider the current the module requires to startup. There is no way the arduino pins can supply such amount of current.

What’s the Solution?

The solution is actually pretty simple. First, I got a hint somewhere that I could take advantage of a diode to reduce the voltage. That’s superb actually since diodes typically have a forward voltage of 0.7v. With two diodes, I can drop the 5v supply to 3.6v. Cool. For the supply, I made use of a 5v 2A supply. (just another phone charger,with the micro-USB end cut off and connected to a breadboard).

<insert pic of circuilt here and perhaps circuit diagram too>

The Arduino side of things.

Upload this on the arduino

#include <SoftwareSerial.h>

SoftwareSerial SIM800(8,7);

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

while(!Serial);

SIM800.begin(9600);

delay(1000);

Serial.println(“Setup Complete”);

}

void loop() {

// put your main code here, to run repeatedly:

if(SIM800.available()){

Serial.write(serialSIM800.read());

}

if (Serial.available()){

SIM800.write(Serial.read());

}

}

Connections

Connect the D8 of the arduino to the SIM800 TX pin and the D7 of the arduino to the SIM800 RX pin. Make sure to connect the ground of both modules to each other – they should share a common ground.

Connect the VCC of the sim to the 5v supply but with 2 diodes in series. Connect the ground to the power supplies ground. Your module should come on.

Make sure the arduino is connected and the code above has been uploaded successfully. Open your serial monitor. After a short while, you should see “Setup Complete”, to test that your setup works, type AT and press send. You should get ok as a response. You are good to go. You can now experiment with other AT commands.

Updates

It still doesn’t work with a sim. It can’t see the two sims I have put in it. I can’t make calls. Perhaps I need a special kind of sim. Sigh.

References.

I adapted code from http://www.ayomaonline.com/programming/quickstart-sim800-sim800l-with-arduino/

Pro Mini vs. Nano vs. Uno

I recently acquired new hardware components among them are some arduino nanos and pro minis. I got them because I wanted to investigate their use as low-cost alternatives to the uno. The uno is about $25 dollars , and you could get clones for as low as $15 but the nano cost about $2. $2 !!

So what’s the same? 

First, they all (or have a version ) run on a 5v. They share the same microcontroller core- the Atmega328 .They have the same number of analog input pins. Some of the digital pins can do PWM. And A4 and A5 can be used for I2C .

What’s different?

One difference is that the uno has max 20mA per digital I/O pin. The Nano and the Pro mini have max 40mA per digital I/O pin.The pro-mini doesnt have an on-board 3.3v regulator. Asides from that, there are hardly any differences between the boards.

So why the price disparity?

Well, the Uno is bigger and has components that enable it connect to a power jack. I would say if you are cost-conscious and don’t need any specialized functionality, go for the pro-mini or the nano. There are smaller, cost less and are just as cool!

References.

https://www.arduino.cc/en/Main/ArduinoBoardUno

https://www.arduino.cc/en/Main/ArduinoBoardNano

https://www.arduino.cc/en/Main/ArduinoBoardProMini

 

Hardware education so far

So I shifted focus back to hardware. I have been doing a lot of software; practising python on hackerrank, learning c/c++ and solving project euler questions. I picked up two books to start with – Designing Embedded Hardware and Embedded Hardware Know it all. They were good at the start but started getting hard to grasp towards the middle. It was a lot to ask to go through them thoroughly cover to cover. I have now decided to not do that.

In Designing Embedded Hardware, I felt the knowledge would be lost since I wasn’t getting hands-on with the processors that were discussed. I have gone through the book cover to cover but I skipped some parts, I would reference them when I need them.

I am back to treating Embedded Hardware Know it all as reference material too. I’m sure that’s what the authors intended but I felt I could understand it all. I like the early chapters and I would be reviewing the notes I made from them. I plan to read the early chapters of Embedded Software know it all too and leave the rest till I need it or I am ready to focus on understand a particular topic.

What next?
I need to refresh my knowledge of electronics. There might be little details I might be missing. I just understood what it means for a pin to be tristate. I want to make sure I fully grasp things like that. I am going to be studying opensource designs – hardware and software. I have already started with the arduino. I believe understanding what exists would help when one wants to design his own systems. I better appreciate how far I have to go. I am going to also do some simple projects with the electronics I have with me at the moment. I don’t want to just follow some tutorial and I dont want to just hack and get it to work (that’s cool by the way). I want to actually understand and engineer stuff. The goal is Mastery.

Understanding the Arduino Hardware

I will attempt to explain how the hardware works in this piece as far as I understand it at the moment.

Arduino2

ArduinoSch

So I decided to understand how the arduino works behind the scenes. I wanted to know what components it was made up of and how the components come together to form the whole system. Like every complex system , it is modular. There is the power system, that chooses between the power jack and the USB power and produces 5v and 3v3 for the rest of the system. There is a USB to serial controller that contains the bootloader which is used to load programs into the ATMEGA328P.

The Power System

Power1

If there is a power suply connected to the power jack. The power supply should be between 9v and 15v. The two chips are voltage regulators that produce 5v. I still dont understand why there are two voltage regulator chips.

The Vin is directly connected to the power supply.

Power2

Vin is connected to the LM385D chip which contains two op amps. One of the opamps is used as a comparator and the other is not used at all. 3V3 is compared to Vin/2 if Vin/2>3V3 then the output is 5v and that is used to turn off the supply from the USB. The 5v generated is then connected to the LP2985 chip which is a voltage regulator that takes in 5v and outputs 3v3 .

If instead Vin/2<3.3 , the mosfet is turned on and the USB power is used instead. USB provides the 5v to the LP2985 chip.

And that’s the power system.

USB to Serial Controller

The USB controller is implemented with the ATMEGA8U2-MU. It contains the bootloader code which is used to load the code unto the ATMEGA328P.

USBController

This includes support circuitry like the silicon crystals and the pull-up resistors. There is also the ICSP interface that can be used to program the chip. The ICSP connects to the microcontroller SPI interface.

The ATMEGA328P

This is the main controller. The code you write for the arduino is executed by this controller. And it is directly connected to the I/O pins. The controller is programmed via the TX,RX pins connected to the USB to serial controller

ATMEGA328P

 

And that’s it. This is relatively high level explanation. I will stop here for now. Next up, would be an explanation of the software.

 

Understanding the Adafruit DHT Library

I was working on a getting an IoT demo running on the raspberry pi and so I downloaded the Adafruit DHT library. I want to be able to create libraries like this in future so I took a peek inside.

The Adafruit DHT library is written in Python with C extensions. The C code is used to communicate directly to the DHT sensor and I would assume the reason for this is that C code is faster than Python code in general (always? ). The Python code is written with several layers and it works with the Raspberry Pi 1, the Raspberry Pi 2 and the Beaglebone black.

DescriptionOfCodeStructure

It starts with the __init__.py file. This file contains just one line of code

from common import DHT11, DHT22, AM2302, read, read_retry

The point of this is to make it possible to refer to Adafruit_DHT.read(). The common.py file detects the platform on which the program is run ( Pi 1, Pi2, or Beaglebone) and then call the appropriate read function for each one. Platform specific code is under the files named Raspberry_Pi.py, Raspberry_Pi_2.py and the Beaglebone_black.py. These files are now used to make calls to C extensions installed by setup.py. setup.py installs C extensions based on _Raspberry_Pi.c and other files on the same level (check the diagram). _Raspberry_Pi.c contain details of the interface between the C and Python code. pi_dht_read.c takes care of communication with the DHT sensor. The pi_mmio.c is a fast memory-map for memory-mapped io (I am yet to understand why this is required or what it really means).

What I liked was the beauty and the structure of the program, it was very well organized and it reminds me of one of the lessons I learnt from SICP about how programs are built in layers of abstraction. As it is, it wont be hard to extend this library for another platform just because of the way it is written. Bravo!

I need to imbibe and do this in my own programs

You can find the code on github here