Tuesday, February 19, 2019

LCR-T4 Oscillator Upgrade

We will replace the 8MHz crystal with a 16MHz one on LCR-T4 transistor tester.  ATMega328p can run up to 20MHz.  The old firmware still seems to run with the 16MHz, but some measurements are off.  Maybe it can be fixed with calibration, but we'll just update the firmware.

The OP_MHZ parameter in the makefile defines the operating frequency of the CPU.  We change it to 16 from 8.  Now we can also enable crystal and ceramic resonator test by defining WITH_XTAL. Only 16MHz and 20MHz are supported for crystal test at this time.   F_CPU, F_CPU_HZ and MHZ_CPU are in turn defined by OP_MHZ. 

After compilation, the program size is shown to be 95.1% full, grown 2290 bytes.  The I2C display version no longer fit in the flash, exceeded by 216 bytes.
Program:   32984 bytes (100.7% Full)(.text + .data + .bootloader)
Data:        210 bytes (10.3% Full)(.data + .bss + .noinit)
EEPROM:      912 bytes (89.1% Full)(.eeprom)
So we disable the crystal test for now, and it is 93.5% full.   After programming the flash, it runs fine.

Now we'll try to trim the code a little so we can enable the crystal test.  Before doing any size optimization, we'll try to remove some features.  Looking the memory map, removing select_color() function would yield enough saving.  We change the compile option undef LCD_CHANGE_COLOR, which saves 586 bytes.  Now we have 370 bytes to spare.
Program:   32398 bytes (98.9% Full)
(.text + .data + .bootloader)
Data:        206 bytes (10.1% Full)
(.data + .bss + .noinit)
EEPROM:      887 bytes (86.6% Full)
(.eeprom)
We can test the XTAL function.  The crystal that we replaced is measured 8000.00KHz, not bad!  A 10MHz series resonance crystal is measured 9999.77kHz series and 10.0018MHz parallel.  But it seems that it cannot measure beyond 10MHz.

We further replace the crystal with a 20MHz one.  Now when we measure the 16MHz crystal, we get 15.9948MHz series, 15.9979MHz parallel.  However, other lower frequency crystals are measured incorrectly.  We'll look into it.


Tuesday, February 12, 2019

Garmin LIDAR Lite

We'll interface Garmin LIDAR Lite with esp32-pico-kit.  esp32-pico-kit interfaces the LIDAR using I2C.   We'll make use of the wireless connectivity.  First we'll transmit the data through Bluetooth.  And we'll the esp32-pico a webserver that'll display the data through WiFi.

The LIDAR runs on 5V, but itself I2C signal is 3.3V, which matches esp32.

We'll use Garmin's LIDARLite_Arduino_Library .  First, we'll try out the library example GetDistanceI2C.  It compiles and is uploaded without a problem.  After hooking up the I2C and 5V, the serial monitor spits out numbers.  For this, the Arduino serial plotter is a great tool to view the output.

Next we'll try to run esp32-pico-kit as a Bluetooth serial device.  We run the SerialToSerialBT example without a problem.  We have two way communications with a Bluetooth serial app on a smart phone.

Then we'll try an example of setting up a WiFi access point.  That also goes without a problem.

Now we have tested the major pieces and are ready to put them together.  We'll start with the LIDAR and BT serial.  That uses 72% of Flash and 12% RAM.  It works nicely .

We'll create a webserver to display the range data next.  We set the web page to auto refresh every second.   It uses 51% of Flash and 11% RAM.  It works just fine.  A lot of features can be added, such as displaying a live graph and changing registers etc.

The ease of create a working IoT system with arduino is quite amazing.