2022-06-25

Beitian BN-880 GPs and Compass Module Experiments - Part III - Tying It Up

 So here it is, the schematic & code for the final assembly (well, final for now ;) )

A warning: the code is a quickly hashed together dog's breakfast of source. It works, but it's very ugly.



 The GPS wiring is exactly the same as the first article, and the wiring for the GLCD
is exactly the same as the last article.




 

Here's the link to the video:


Here's the Source:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

#include <Arduino.h>
#include <U8g2lib.h>
#include <SPI.h>
#include <Wire.h>

// Variables for the GPS module
static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;
char zs[32] = "";
int x = 0;
int y = 0;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

U8G2_ST7920_128X64_1_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 8);

void setup(void) {
  ss.begin(GPSBaud);
  u8g2.begin();
  u8g2.clearBuffer();
}

void loop(void) {
  u8g2.firstPage();
  do {
    u8g2.setFont(u8g2_font_squeezed_r6_tr);
    printInt(5, 15, gps.satellites.value(), gps.satellites.isValid(), 5);
    printFloat(5, 25, gps.location.lat(), gps.location.isValid(), 10, 7);
    printFloat(5, 35, gps.location.lng(), gps.location.isValid(), 10, 7);
    printDateTime(5,55, gps.date, gps.time);

  } while ( u8g2.nextPage() );
  smartDelay(500);
}

/*----------------------------------------------------------------------*/
/* All functions/subroutines are below this comment section             */
/*----------------------------------------------------------------------*/


// This custom version of delay() ensures that the gps object
// is being "fed".
static void smartDelay(unsigned long ms)
{
  unsigned long start = millis();
  do
  {
    while (ss.available())
      gps.encode(ss.read());
  } while (millis() - start < ms);
}

static void printFloat(int x, int y, float val, bool valid, int len, int prec)
{

  if (!valid)
  {
    while (len-- > 1)
    u8g2.drawStr(x, y, '*');
    u8g2.drawStr(x, y, ' ');
  }
  else
  {
    dtostrf(val, len, prec, zs);
    u8g2.drawStr(x, y, zs);
    int vi = abs((int)val);
    int flen = prec + (val < 0.0 ? 2 : 1); // . and -
    flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1;
    for (int i=flen; i<len; ++i)
      u8g2.drawStr(x, y, ' ');
  }
  smartDelay(0);
}

  static void printInt(int x, int y, unsigned long val, bool valid, int len)
{
  char sz[32] = "*****************";
  if (valid)
    sprintf(sz, "%ld", val);
  sz[len] = 0;
  for (int i=strlen(sz); i<len; ++i)
    sz[i] = ' ';
  if (len > 0)
    sz[len-1] = ' ';
    u8g2.drawStr(x, y, "Sats: ");
    u8g2.drawStr(x+17, y, sz);

  smartDelay(0);
}

static void printDateTime(int x, int y, TinyGPSDate &d, TinyGPSTime &t)
{
  if (!d.isValid())
  {
    u8g2.drawStr(x, y, "Time: ********** ");
  }
  else
  {
    char sz[32];
    sprintf(sz, "GMT Time: %02d/%02d/%02d : %02d:%02d:%02d", d.month(), d.day(), d.year(), t.hour(), t.minute(), t.second());
    u8g2.drawStr(x, y, sz);
  }
  smartDelay(0);
}


Like I said: It's ugly.

じゃまた

2022-06-20

Beitian BN-880 GPs and Compass Module Experiments - Part II

 In Part two of the Beitian BN-880 GPS/Compass module, I set up a GLCD module for use with the Arduino, this time, however, we won't see the GPS (at least, not this time) this is all about getting the GLCD working.

Here is the wiring diagram:



 

 

I haven't added the BN-880

to this conglomeration yet,

but will do that in the next post.





Here is the code:

#include <Arduino.h>
#include <U8g2lib.h>

#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif

// 'TheOffice', 128x64px
static const unsigned char myBitmap [] PROGMEM = {

   0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0x3f, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x06, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc7,
   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0x9f, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb8, 0x03, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0xb0,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3f, 0x00,
   0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xb0,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x80, 0x7f, 0x00,
   0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0x00, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0xb0,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xc0, 0x7f, 0x00,
   0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0xf0, 0xff, 0x03, 0x00, 0x00, 0x00, 0xb0, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x07, 0x00, 0x00, 0x7c, 0xb0,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x07,
   0x00, 0x00, 0xfe, 0xb0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0xf8, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb0, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb0,
   0x81, 0xff, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0xf8, 0xff, 0x0f,
   0x00, 0x00, 0xfe, 0xb0, 0x81, 0xff, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0xf8, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xb0, 0x81, 0xff, 0x1d, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0xb0,
   0x01, 0x38, 0xdc, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x0f,
   0x00, 0x00, 0x7c, 0xb0, 0x01, 0x38, 0xfc, 0xf3, 0x03, 0x00, 0x00, 0x00,
   0x08, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0x38, 0xb0, 0x01, 0x38, 0xfc, 0xfb,
   0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x0f, 0x00, 0x00, 0xfc, 0xb0,
   0x01, 0x38, 0x9c, 0x3b, 0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x07,
   0x00, 0x00, 0xfe, 0xb0, 0x01, 0x38, 0x9c, 0xfb, 0x07, 0x00, 0x00, 0x00,
   0x08, 0xfc, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb7, 0x01, 0x38, 0x9c, 0xfb,
   0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x07, 0x00, 0x00, 0xfe, 0xb7,
   0x01, 0x38, 0x9c, 0x3b, 0x07, 0x00, 0x00, 0x00, 0x08, 0xfc, 0xff, 0x07,
   0x00, 0x00, 0xfe, 0xb7, 0x01, 0x38, 0x9c, 0xfb, 0x07, 0x00, 0x00, 0x00,
   0x08, 0xfe, 0xff, 0x07, 0x00, 0x00, 0xff, 0xb7, 0x01, 0x38, 0x9c, 0xf3,
   0x03, 0x00, 0x00, 0x00, 0x08, 0xfe, 0xff, 0x07, 0x00, 0x80, 0xff, 0xb7,
   0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00,
   0x00, 0xc0, 0xff, 0xb6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0xc8, 0xff, 0xff, 0x00, 0x00, 0xe0, 0xff, 0xb6, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00, 0x00, 0xfe, 0xff, 0xb6,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00,
   0xc0, 0xff, 0xff, 0xb6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0xc8, 0xff, 0xff, 0x00, 0xe0, 0xff, 0xff, 0xb6, 0x01, 0xf8, 0x07, 0xbe,
   0xff, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0x00, 0xe0, 0x7f, 0xff, 0xb7,
   0x01, 0xfc, 0x1f, 0xbf, 0xff, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0xfc,
   0xff, 0x0f, 0xff, 0xb7, 0x01, 0xfe, 0x1f, 0xbf, 0xff, 0x00, 0x00, 0x00,
   0xc8, 0xff, 0xff, 0xfc, 0xff, 0xef, 0xff, 0xb7, 0x01, 0x1f, 0x3e, 0x8f,
   0x03, 0x00, 0x00, 0x00, 0xc8, 0xff, 0xff, 0xc0, 0x01, 0xfe, 0xff, 0xb7,
   0x01, 0x0f, 0xbc, 0xff, 0xef, 0xf0, 0x87, 0x1f, 0xc8, 0xff, 0xff, 0xc0,
   0x01, 0xff, 0xff, 0xb7, 0x01, 0x0f, 0xbc, 0xff, 0xef, 0xf8, 0xcf, 0x3f,
   0xc8, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xb7, 0x01, 0x0f, 0xb8, 0xff,
   0xef, 0xfc, 0xef, 0x3f, 0xc8, 0xff, 0xff, 0xc0, 0x01, 0xff, 0x7f, 0xb7,
   0x01, 0x0f, 0x38, 0x8f, 0xe3, 0x3c, 0xef, 0x79, 0x08, 0xc0, 0x7f, 0xc0,
   0x81, 0xff, 0x1f, 0xb7, 0x01, 0x0f, 0x3c, 0x8f, 0xe3, 0x3c, 0xe0, 0x7f,
   0x08, 0xc0, 0x7f, 0xc0, 0x81, 0xef, 0xff, 0xb7, 0x01, 0x0f, 0x3c, 0x8f,
   0xe3, 0x1c, 0xe0, 0x7f, 0x08, 0xc0, 0x7f, 0xc0, 0x81, 0xef, 0xff, 0xb7,
   0x01, 0x1f, 0x3c, 0x8f, 0xe3, 0x3c, 0xe6, 0x7f, 0x08, 0xc0, 0x7f, 0xc0,
   0x81, 0xe7, 0xff, 0xb7, 0x01, 0x3e, 0x3e, 0x8f, 0xe3, 0x3c, 0xef, 0x79,
   0x08, 0x80, 0x7b, 0xc0, 0xc1, 0x67, 0x00, 0xb7, 0x01, 0xfe, 0x1f, 0x8f,
   0xe3, 0xfc, 0xef, 0x7f, 0x08, 0x80, 0x33, 0xc0, 0xc1, 0x67, 0x00, 0xb7,
   0x01, 0xfc, 0x0f, 0x8f, 0xe3, 0xf8, 0xcf, 0x3f, 0x08, 0x00, 0x00, 0xc0,
   0xc1, 0x67, 0x00, 0xb7, 0x01, 0xf8, 0x07, 0x8f, 0xe3, 0xf0, 0xc7, 0x1f,
   0x08, 0x00, 0x00, 0xc0, 0xe1, 0x63, 0x00, 0xb7, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0, 0xe1, 0x63, 0x00, 0xb7,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0,
   0xe1, 0x61, 0x00, 0xb7, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x08, 0x00, 0x00, 0xc0, 0xe1, 0x61, 0x00, 0xb7, 0x01, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0, 0xe1, 0x61, 0x00, 0xb7,
   0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0xc0,
   0xe1, 0x60, 0x00, 0xb2, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x03, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0,
   0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0xbc, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0xe0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcf, 0x06, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0,
   0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   0xff, 0xff, 0xff, 0x7f
};


U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, /* clock=*/ 13, /* data=*/ 11, /* CS=*/ 10, /* reset=*/ 8);


void draw(void)
{
  u8g2.drawXBMP( 0, 0, 128, 64, myBitmap);
}


void setup() 
{
  // put your setup code here, to run once:
  u8g2.begin();
  u8g2.clearBuffer();
}

void loop()
{
  // put your main code here, to run repeatedly:
  u8g2.firstPage();
  do
  {
    draw();
  }while(u8g2.nextPage());

  delay(1000);

}

I scavenged this code from here:

Interface as 128c64 GLCD with an arduino

Here is a link to my Vlog:




Enjoy!


じゃまた

2022-06-06

Perelandra - C.S. Lewis - A New Eden, A New Adam, A New Eve, Same Old Serpent.

A quick book review of "Perelandra" By C. S. Lewis.

Blog Archive

Contributors

CatWalker

CatWalker
CatWalker at 29