LTE project gets a status bar!

In my continuing effort to learn about programming, cellular service, and Arduino, I’ve made a couple of great developments on my LTE project. Essentially, I’m turning these parts into a texting/gps device. I want to say a phone, but since it uses LTE only, it can’t actually make a phone call. So it is a “smart device” rather than a “smart phone”.

Of course, any useful device needs to have a status bar. And that is what I have done so far. The Nokia 5110 display, at the current font, supports 5 lines of text. So, I decided the top line will always be the status bar. Just like your smart phone, this device uses a status bar to tell you the “status” of everything you really, really need to know in one glance.

The first digits displayed are the battery percentage. If you don’t know how much time you have left on the device before it dies, it can be a little hard to use. Here you can see the magic behind the curtain:

// Get the battery percentage:
uint16_t vbat;
if (! fona.getBattPercent(&vbat)) {
Serial.println(F(“Failed to read Batt”));
lcd.print(“**% “);
} else {
Serial.print(F(“VPct = “)); Serial.print(vbat); Serial.println(F(“%”));
lcd.print(vbat); lcd.print(“% “);
}

Next up is the GPS indicator. Note that this doesn’t tell you if you have a lock, but does tell you if the battery draining GPS is turned on or off (GPS for on, — for off). Fortunately, the fona library includes a GPS status checking function, so we just call it, like so:

// Get the GPS status:
int statGPS = fona.GPSstatus(); Serial.print(F(“GPS status = “)); Serial.println(statGPS);
if (statGPS == 1) {lcd.print(“GPS “);} else {lcd.print(“— “);}

After that, we have the network status indicator. I’ll delve into that a bit more. It looks like the traditional multi-bar display, but unlike traditional ones on your smart phone, this actually is just full bars, or not. As you can see, you can get different letters for different status, or just the home made bar indicator glyph for roaming or home connections.

// Get the network status:
uint8_t n = fona.getNetworkStatus();
Serial.print(F(“Network status “));
Serial.print(n);
Serial.print(F(“: “));
if (n == 0) {Serial.println(F(“Not registered”)); lcd.print(“X”);}
if (n == 1) {Serial.println(F(“Registered (home)”)); lcd.write(0);}
if (n == 2) {Serial.println(F(“Not registered (searching)”)); lcd.print(“S”);}
if (n == 3) {Serial.println(F(“Denied”)); lcd.print(“D”);}
if (n == 4) {Serial.println(F(“Unknown”)); lcd.print(“?”);}
if (n == 5) {Serial.println(F(“Registered roaming”)); lcd.write(0);}
lcd.print(” “);

Finally, there is a number that tells you how many text messages you currently have.

// Get the number of SMS messages:
int8_t smsnum = fona.getNumSMS();
if (smsnum < 0) {
Serial.println(F(“Could not read # SMS”));
lcd.print(“-0- “);
} else {
Serial.print(smsnum); Serial.println(F(” SMS’s on SIM card!”));
lcd.print(smsnum);
}

You are welcome to check out the whole commit, but this is the gist of how the status bar works. Currently, the sketch takes up 78% of the Arduino’s memory. I think the direction I am going with this is trying to make a beginning to end, build at home smart device that allows you to at lease navigate by GPS, and send/receive text messages.

If wishes were fishes, and moose’s excuses, I guess we would all have full freezers. With that said, if I am able, I wish I could work in a couple other simple tasks as well, such as a way to play a simple game, perhaps check an email, or maybe a very rudimentary e-link style web browser. But I think that might be a whole lot more than I can realistically accomplish with so little memory on the device. We’ll see though!

Linux – keep it simple.

Arduino LTE Botletics shield and a Nokia 5110 display!

image2

Today was a lot of fun, and I mean a lot! I was able to connect not only the Botletics LTE shield, but also the Nokia 5110 screen to the Arduino, AT THE SAME TIME! I know, for the rest of the Arduino enthusiasts out there, this may seem like child’s play, but it was a big deal for me.

First, I was using the Botletics modified fona library, and with the soldered board pins, it can only connect to the Arduino one way. The problem was that I was also using the PCD8544 library to control the Nokia 5110 display, but some of the pins needed were the same ones for both devices. That certainly wouldn’t do. So, I edited the PCD8544.h file as follows:

PCD8544(uint8_t sclk = 3, // clock (display pin 2)
uint8_t sdin = 4, // data-in (display pin 3)
uint8_t dc = 5, // data select (display pin 4)
uint8_t reset = 12, // reset (display pin 8)
uint8_t sce = 13); // enable (display pin 5)

Changing these pin outs allowed me to control it with the remaining pins on the board. Now I can have both the display and the LTE shield at the same time! Essentially, the old PCD8544 library had used pins 3,4,5,6, and 7, for simplicity. I however couldn’t use 6 and 7, as those were taken by the LTE shield. So, I swapped them in the header file to point to pins 12 and 13, since they were not being used.

The only problem I ran into, though, was space. It takes a lot of space for the fona library to run the LTE shield. Originally, I was going to use the U8 library, but using those two together actually took 109% of the storage space on the Arduino Uno. I tried to trim down the portions of code for the fona side, but couldn’t get everything small enough. Fortunately, the PCD8544 library was much, much smaller, and I found that it even has a simpler interface for text only, which is mostly what I want to use the screen for.

With those two libraries pared up, I added some lines to my LTE demo sketch to allow me to display the battery information on the Nokia 5110 screen. All told the sketch uses 26470 bytes (82%) of the program storage space, the maximum is 32256 bytes. It worked great, looked good, and still leaves room for more programming.

You can check out the full commit, of course, but here is the portion about the screen:

case ‘b’: {
// read the battery voltage and percentage
uint16_t vbat;
if (! fona.getBattVoltage(&vbat)) {
Serial.println(F(“Failed to read Batt”));
} else {
lcd.setCursor(0, 0);
lcd.print(“Battery Status”);
Serial.print(F(“VBat = “)); Serial.print(vbat); Serial.println(F(” mV”));
lcd.setCursor(0, 1); lcd.print(“VBat = “); lcd.print(vbat); lcd.print(” mV”);
}

if (! fona.getBattPercent(&vbat)) {
Serial.println(F(“Failed to read Batt”));
} else {
Serial.print(F(“VPct = “)); Serial.print(vbat); Serial.println(F(“%”));
lcd.setCursor(0, 2); lcd.print(“VPct = “); lcd.print(vbat); lcd.print(“%”);
}

break;
}

Really simple commands to set up the cursor, and then just lcd.print to display information. I really like this simple screen library for text. It doesn’t handle graphics too well, though, which is what the U8 library excelled at.

So I guess now I need to work out some sort of menu system, as well as some sort of buttons if I want to turn this thing into a portable texting/gps/data interface device.

Linux – keep it simple.

Drawing variable circles with an Arduino Uno and a Nokia 5110 LCD

I’m still trying to catch up on some of my new toys that I bought/got around Christmas time. I know, I’m four months behind! One of those gadgets was a Nokia 5110 LCD screen, and this thing is fun! It looks like something they used to use in old Nokia cell phones, and it works great for a monochrome, low resolution display.

I’m driving it with an Arduino Uno board. At first, to make sure I understood how to use it, I watched InterlinkKnight’s Youtube tutorial, which you also should check out. It was very clear, highly informative, and really well put together.

After watching the tutorial, and loading the library and his sketches, I then set out to make my own. I noticed a couple of things that were noteworthy for the new user, so I thought I’d share them here.

First, you need the library. You can get it here: https://github.com/olikraus/U8glib_Arduino

Just unzip the library, and put it in your Arduino library folder (unzipped, of course). For me, on my Ubuntu Linux machine, that was in /home/alaskalinuxuser/Arduino/libraries/, where I just dropped off the unzipped folder from U8. If you don’t put this in your Arduino libraries, it can’t find the referenced include file, and this wont work.

Then I made my own sketch:

/*
This is an example on how to use the display known as Nokia 5110 SPI with PCD8544 driver using the U8GLIB library.

Nokia 5110 SPI display pins for Arduino Uno/Nano:
* RST = 8
* CE = 10
* DC = 9
* DIN = 11
* CLK = 13
* VCC = 5V
* BL = 3.3V
* GND = GROUND

We use this library: https://github.com/olikraus/U8glib_Arduino

User Reference Manual: https://github.com/olikraus/u8glib/wiki/userreference

List of fonts: https://github.com/olikraus/u8glib/wiki/fontsize

Sketch Originally made by: InterlinkKnight
This sketch was featured on his video tutorial for this display: https://www.youtube.com/watch?v=1ZvY_lb6BoU
Last modification: 11/22/2017

Sketch modified by alaskalinuxuser
Last modification: 04/02/2019
*/

#include “U8glib.h” // Include U8glib library
// Create display and set pins:
U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // (CLK=13, DIN=11, CE=10, DC=9, RST=8)

int Variable1; // Create a variable to have something dynamic to show on the display
int fadeAmount = 1; // how many points to change by

void setup(void) // Start of setup
{

// Select a font:
u8g.setFont(u8g_font_profont12);

// Change display orientation:
//u8g.setRot90();
u8g.setRot180();
//u8g.setRot270();

} // End of setup

void loop(void) // Start of loop
{
// wait for 25 milliseconds to see the dimming effect
delay(25);

// change the brightness for next time through the loop:
Variable1 = Variable1 + fadeAmount;

// reverse the direction of the fading at the ends of the fade:
if (Variable1 <= 0 || Variable1 >= 45) {
fadeAmount = -fadeAmount;
}

u8g.firstPage(); // Beginning of the picture loop
do // Include all you want to show on the display:
{
u8g.drawCircle(41, 21, Variable1, U8G_DRAW_ALL); // Draw a circle (x,y,radius,option)

u8g.drawRFrame(59, 10, 25, 13, 3); // Draw a rounded square (x,y,width,height,radius)

// Variable with left text alignment:
u8g.setPrintPos(63, 20); // (x,y)
u8g.print(Variable1); // Value to print
} while(u8g.nextPage()); // End of the picture loop

} // End of loop

The key part of what I was playing with, was using a variable to set the circle size. Every run of the loop, after a slight delay, the circle is increased or decreased in size to make it grow or shrink on the screen. This makes a very nice “pulse” effect. Most of the code here was originally in InterlinkKnight’s sketch, I just modified it for my use, and added a variable changer.

Another thing I noticed was the back lighting. On my Nokia 5110, it is labeled as “BL” which means you apply voltage to it to illuminate the back lighting of the screen. In his tutorial, he rightly mentioned that you could use 5 volts here, which works great, but I found it to be obnoxiously bright. Instead, I used the 3.3 volt output from the Uno, and that was much better on the eyes. The screen will work without the back lighting, but then you need ample light to view it.

I’m seeing some fun potential with this screen!

Linux – keep it simple.