Showing posts with label BC-95. Show all posts
Showing posts with label BC-95. Show all posts

Tuesday, March 20, 2018

Peeling the Banana

March 20, 2018 Posted by Akalanka , , 1 comment
The banana PI is a tiny powerhouse with its powerful STM32 microcontroller and integrated NB-IoT modem. In this post we will go bit more in depth to see what this tiny board has on offer. 

Power source

The STM32F103RBT6 controller in the Banana should be powered from a stable voltage source between 2.0V and 3.6V. You can supply power via

  • USB connector from PC or power bank
  • Vcc GND pins in SWD header up to 3.6V
  • Battery connector up to 3.6V

The recommended operating voltage should be adhered to as indicated in the datasheet to keep the little STM happy.



I/O Pins
There are 51 I/O pins available in the STM32 and many of them can be found in the 40 pin GPIO header in the Banana. It the very important to note that not all pins are 5V tolerant. As indicated in the table above, the input voltage for 5V tolerant pins should be less than 5.5V. and only 3.3V for non 5V tolerant pins. The voltage levels of the peripherals connected to the I/O pins should be carefully checked to avoid damaging the STM32. It is always advisable to use a logic level converter for converting 5V to 3.3V or use peripherals that run off 3.3V to avoid destroying the microcontroller.

The 40 pin header layout is as follows:


When programming in Arduino IDE the pin name (eg:PC1) can be directly used in pinMode(), digitalWrite() and digitalRead() functions.

USART ports

The Banana has 3 USART ports in addition to the virtual USART port (USART0) which is visible over the USB when connected to the PC.

  • USART0 - virtual COMM port visible only when connected to PC via USB
  • USART1 - 5V tolerant
  • USART2 - Not 5V tolerant, used for modem communication and should be used with external devices
  • USART3 - 5V tolerant
I2C ports

The Banana has 2 I2C modules where both are 5V tolerant


SPI ports

The Banana has 2 SPI modules where SPI1 is only 3.3V but SPI2 is 5V tolerant

Onboard LEDs

The Banana has 4 on board LEDs for status indication etc.
  • LED1 - PC0
  • LED2 - PC1
  • LED3 - PC2
  • LED4 - PC3
Reset button
This button is self explanatory since it pulls the RESET pin low to reset the microcontroller

Power button
This button, even though named as the power button on the board pulls down the PD2 pin on the microcontroller when pressed. It is up to you to use it as a trigger or a power key in the firmware.




Sunday, March 18, 2018

NB-IoT with Inzpire

March 18, 2018 Posted by Akalanka , , 2 comments

Maintaining communication with remote devices is always a challenge in IoT. Building a IoT solution is always a new exercise because the types of hardware and protocols keep getting updated periodically. A good example is the Constrained Application Protocol (CoAP) which rose to popularity with small devices coming into the picture in Internet of Things. Today we will see how Inzpire can minimize the hassle of connecting your NB-IoT device with your application server.

Why CoAP?
Not all protocols are made the same way. CoAP is a very lightweight protocol optimized for low bandwidth networks. Unlike our good old HTTP which has been a reliable workhorse for more than 90% of our digital interactions with a very verbose protocol, CoAP has a compact packet format based on a binary protocol. Being an application layer protocol it relies on UDP transport for end to end delivery. However since guaranteed delivery is not a thing for UDP, CoAP implements its own simple stop-and-wait type error recovery and congestion control mechanism. If you know about the more sophisticated features offered by TCP such as adaptive flow control, think of CoAP like its slow cousin. But CoAP thrives in a resource constrained environment both on the network and device ends which gives it an edge over TCP in most narrow band applications. In tests we have seen that when operating at the coverage edge with NB-IoT, CoAP request with a 10 byte payload takes less than 3 seconds while a simple HTTP GET request takes in excess of 30 seconds (Yes you saw that right, its 30s, crazy stuff happen when you push the poor modem to the limit). I was initially skeptical on the effectiveness of CoAP, but the results of the above experiment made me think otherwise.

Inzpire to the rescue
Using CoAP comes with its own set of cons. A major one being the lack of experience needed to setup and maintain a CoAP server for device communication. Inzpire NB-IoT solves this problem for you by acting as gateway to forward CoAP messaging to and from HTTP. If you are familiar with how SMS and Voice works in Inzpire you will notice many similarities.


In this article we will see how you can connect your Banana Pi with a BC95 NB-IoT modem to your application through Inzpire NB-IoT. For more info on Banana Pi and NB-IoT refer the previous posts in this blog.

Step 1: Setup an HTTP/MQTT endpoint for device to communicate

HTTP method

You should have a HTTP web server running at a public location for handling up link messages from the device. Once a call is received by your short code or long number an HTTP request will be made from the Inzpire voice server to this server. The URL of this service should be entered in the callback URL in the next step when provisioning a NB-IoT device. The request will be a HTTP POST with the following parameters in a JSON formatted payload in the body
  • deviceId: This is the IMEI of the NB-IoT modem
  • payload:
    • type: data type is Buffer by default
    • data: data payload sent by the device as an array
MQTT method

If you are opting for the MQTT integration, you should have a public MQTT broker for this step. You will receive a publish from the device to the topic that you will provide in the next step. If you are subscribed to that topic with your own favorite MQTT client, you will be able to receive the message.

Step 2: Provision your Banana Pi in Inzpire

Provisioning an NB-IoT device in Inzpire is made extremely simple with a single SMS. 
  • HTTP Method:
    • Send NBReg<Space><IMEI of your Banana PI><space><Callback URL> to 77001
  • MQTT Method:
    • Send NBReg<Space><IMEI of your Banana PI><space><MQTT Broker URL><space><MQTT topic> to 77001
  • You will get a USSD prompt indicating that you will be charged a subscription fee for the service
  • Enter S in the USSD prompt and hit send
  • You will receive an SMS with 'Device registered successfully' with a device key.
Step 3: Connect your Banana-Pi , fire up Arduino IDE and start coding

Once your device is registered, simply call the functions related to messaging via CDP in the BC95-Arduino library at https://gitlab.com/akalankadesilva/BC95-Arduino to send messages and receive messages. All the messages that the device sends will be sent as HTTP POST requests to your callback URL.





Using BC-95 for NB-IoT

March 18, 2018 Posted by Akalanka , 4 comments
The BC-95 modem by Quectel is a low cost NB-IoT modem designed to be used in low power applications. This has a chipset by Neul whose parent company is now Huawei. Main highlights of this modem are:

  • Supports NB-IoT in Band 5/8/20
  • Inbuilt stack for UDP, COAP*
  • Support for Non-IP data delivery
  • Downlink max speed: 24kbps
  • Uplink max speed: 15.625kbps
  • AT Command interface via UART
The offered AT commands are quite comprehensive yet simple. You can refer the official page http://www.quectel.com/product/bc95.htm for more details. Important commands to remember are:

Basic AT commands:
  • AT+CFUN - turn modem ON or OFF by setting the functionality
  • AT+NRB - reboot modem
Network registration
  • AT+COPS - set network registration. 
  • AT+CEREG - check network registration status and parameters
Data (PDP) activation & testing
  • AT+CGATT - Attach packet data
  • AT+CGDCONT - set APN
  • AT+NPING - Ping a remote IP address
UDP Datagram 
  • AT+NSOCR - Open UDP socket
  • AT+NSOST - Send UDP message
  • AT+NSORF - Receive UDP Packet
  • AT+NSOCL - Close UDP Socket
CDP (COAP) 
  • AT+NCDP - Set CDP platform settings
  • AT+NMGS - Send CoAP message via platform
  • AT+NNMI - Received message indicator
  • AT+NMGR - Get received messages

A sample command sequence would be 
  • AT+NRB - Start with a reboot 
  • AT+COPS? - Check if connected to network
  • AT+COPS=1,2,"41301",7 - Make the modem attache to network manually. "41301" are the MCC & MNC for Mobitel Sri Lanka
  • AT+CGATT=1 - Start data session
Once this is complete you can either send UDP messages or CoAP messages using appropriate commands. 

Important: If the modem you have at hand is not registering on a network check the following - 
  • Enter AT+NCONFIG?
  • Check if the 'scrambling' parameter is set to false. If not enter
    • AT+NCONFIG="CR_0354_0338_SCRAMBLING","FALSE" 
  • Enter AT+NUESTATS to check the current modem status in the radio layer.
  • You can set the 'auto connect' parameter in NCONFIG to true so that once the modem is powered up it will auto attach to the network.
This is caused by the different ways the operators configure their network. Prior to 3GPP release 13 (R13) scrambling could be turned on on the network as an option. But R13 mandated turning on scrambling which meant the scrambling status should be configured depending on your NB-IoT service provider. However even this minor ambiguity is expected to be ironed out when complete R13 compliance is reached.

Connecting your BC-95 to Arduino

If you are using Arduino and want to connect to your BC-95, you are in luck. We have a simple Arduino library for you to give the head start at https://gitlab.com/akalankadesilva/BC95-Arduino 

Refer the bc95test.ino in the GIT for sample codes to send UDP messages and CoAP messages to remote servers. In the next post we will see how to communicate with a BC-95 based device using Inzpire NB-IoT device API.



Go bananas with Banana Pi!

March 18, 2018 Posted by Akalanka , , No comments
We went through the names of few NB-IoT modems currently available in the market in our last post. And then we laid our hands on this interesting piece of circuitry called the Banana Pi. If you are into the whole single board computer thing you might think its a raspberry pi knockoff. The initial banana pi is actually a single board computer similar to the raspberry pi and the orange pi (yes <fruit name> +pi is a naming convention for SBCs) with a ARMv7 processor running linux. Now Banana Pi is a popular brand in the industry and many different models with an array of ARM processors can be found. The banana pi we have  is not a single board computer, but a microcontroller board with a powerful STM32 series microcontroller. Turn it around and you will see a BC-95 NB-IoT modem in all its awesomeness.
To add to the excitement you will see that it has a 40 pin header for I/O pins and a battery terminal for directly connecting a 3.7V li-ion cell or couple of AA cells. All these are essential ingredients for a neat IoT device comes in a small 60mm x 30mm package.

In summary the Banana PI Linaro has
  • STM32F103R microcontroller running at 72MHz
  • 128kB program flash memory 
  • 20kB SRAM
  • 51 GPIOs
  • UART
  • I2C
  • SPI
  • PWM
  • BC95 NB-IoT Modem
  • 3.7V Li-Ion and 5V power input
  • 5 LEDs + 1 power LED
However the Banana Pi, with its STM32 microcontroller, poses few challenges to the developer unless you are familiar with IDEs like Keil and have access to a STLink programmer. If you are an Arduino fan and is now accustomed to the convenient way that things can get done with an Arduino, trying to learn programming the STM32 with Keil (which is an IDE for ARM based processors) might be intimidating. But the silver lining is that the good guys at Leaf Labs have an Arduino IDE compatible bootloader - Maple and the necessary IDE plugins - libmaple to get you up and running in no time. Let us see how you can setup the Banana Pi Linaro with your favourite Arduino IDE and Maple

Step 1: Install the Arduino board for STM32

In order to use your board with the Arduino IDE, the first step is to install the board definition.
  • Open your Arduino IDE. We tested this on 1.6.10
  • Go to Tools > Board > Board Manager
  • Search for 'Maple Mini' as shown below and install the STM32F1xx by stmduino board

When the board is installed, you will be able to see that there are few board definitions that are added as shown below.

Out of the newly installed boards, we are interested in the STM32F103R series, which is the tiny powerhouse we have in our Banana Pi. Like any other Arduino board you will also get the samples for the board under File >Examples >A_STM32_Examples


Step 2: Install Maple bootloader on microcontroller

If you are lucky enough to get your hands on a Banana Pi with Maple bootloader, you can skip this step. Else read on..
In order to flash a firmware to a microcontroller, usually you need a dedicated programmer for this task such as a PiCKit for PIC microcontrollers and AVR ISP for Atmel AVR microcontrollers. However an easier option is to use a bootloader. A bootloader is a small piece of code that runs for few seconds when the microcontroller is started to check for new firmware over Serial or USB and writes the new firmware to the program memory if available. Arduino has many different bootloaders available for AtMega 328, AtMega 2560 chips by Atmel such as Uno, nano, Mega, Diecimilia etc. in their boards. This makes it very convenient to program a microcontroller right from the IDE (such as Arduino) since it does not need a programmer hardware. All this time you have played with your Arduino, you have been using Atmel chips with Arduino bootloaders programmed via the Arduino IDE. A programmer is needed only to flash the bootloader, which needs to be done only once.

The STM32F103 microcontroller we have in our Banana Pi has its own method of firmware update using a special protocol called DFU. Device Firmware Update (DFU) is a standard protocol used to flash firmware updates to devices over USB. Most middle to high end microcontrollers have in built DFU for conducting firmware updates. The STM microcontroller in our Banana Pi has DFU and in built USB which enables it to flash firmware very easily. This is different to how things are done in an Arduino board with a ATMEL microcontroller where a USB-Serial bridge (FTDI232, PL2303 etc.) connects the host PC USB with the microcontroller USART0. This is because the ATMega 328 or ATMega 2560 microcontrollers in standard Arduino Uno, Nano or Mega boards (except the Leonardo) do not have in built USB ports. Therefore once you plug in the Banana Pi to the PC, it should be detected as a DFU device since DFU device drivers usually comes with any modern Windows OS. We will show how it can be done in Ubuntu in a later post. 

If what you read above sounded greek, fear not, as there is a easy way out. The maple bootloader enables you to use the STM just like an Arduino.To make an STM work with Arduino IDE with the board that we installed in the previous step, you should write the Maple bootloader to the STM which is a one time thing. You can find a good resource on how to install the Maple bootloader at Leaf Labs http://docs.leaflabs.com/docs.leaflabs.com/index.html You will need a STLink programmer for this process. Once the bootloader is flashed to the memory the DFU becomes active after a board reset for a short period for firmware update. If the IDE does not initiate a firmware update, the STM goes on to execute the program code. Now, the board will now be visible as a COM port in your PC just like an Arduino. 


Step 3: Setup Maple drivers on PC

Remember how we said that the board will be recognized as a DFU device by Windows? Most of the time you will need to introduce the drivers to the device in order to be recognized successfully. This is done using a simple tool called 'wdi-simple'. Refer this video https://www.youtube.com/watch?v=0jdJp3TQuJY for step by step instructions and this great github link https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Maple-drivers for more info. Once the drivers are introduced properly, your Banana Pi will be fully functional for firmware update as well as Serial communication just like a our plain old Arduino Uno.



How to connect with NB-IoT

March 18, 2018 Posted by Akalanka , 2 comments

Like any wireless or wired network, NB-IoT requires a modem with NB-IoT capability to reach the network. However unlike a WiFi or Bluetooth modem, NB-IoT requires a SIM card and subscription to a NB-IoT enabled network operator as well. In that it is more similar to an ordinary mobile service subscription. Mobitel, Sri Lanka's national mobile service provider is currently deploying NB-IoT around the island and if you are in Sri Lanka you can contact them to get pointers on how to connect your NB-IoT device.

NB-IoT modem saga

The standardization of NB-IoT was completed by 3GPP (the guys who tell whos who and whats what in telco standardization domain) in mid 2016. Since then we have seen multiple chipset manufacturers hopping on the bandwagon to build NB-IoT enabled chipsets. The first NB-IoT chipset was built by a UK based company Neul which is now acquired by Huawei. Their chipset was later used by popular modem manufacturers like Swiss based u-Blox and China based Quectel. u-Blox introduced the Sara N200,N210 series while Quectel came up with the BC-95. Another giant in the chipset arena, Qualcomm was quick to embark on its own NB-IoT journey with their MDM9206. This chipset is adopted by another very famous name in the modem business, SIMCom in their SIM7000 modem series. Sequans communcations, also a popular brand in modem business has their own single chip modem called the Monarch series. Another Chinese telco equipment giant, ZTE is also in the modem market with their Welink ME3612.

In summary, at the time of writing, we have the following modems for NB-IoT

  • BC 95 by Quectel
  • BG 96 by Quectel
  • SIM7000 by SIMCom
  • N200/210 by u-Blox
  • Monarch N by Sequans
  • ME3612 by ZTE

Each modem comes with its own quirks and features. Some are more developer friendly than others. An important factor to consider is the amount of resources that are available. Large chinese firms such as Huawei are aggressively driving NB-IoT in network side, platform side and device side which means there are more resources than you think if you are willing to learn chinese (I'm kidding the good guys at Google have given us the translator for free) and search in Baidu (yes its their own search engine).
For the interest of our local readers we will go through the most popular modems like N200, BC95 and SIM7000 in our following posts anything else we can get our our hands on. Till then keep hacking!