Saturday, May 30, 2020

ESP01 - Arduino SSD1306 OLED 0.9 inch Library

Create custom Font with selected size usefull link:http://oleddisplay.squix.ch/#/home


1. Arduino library install: Adafruit SSD1306, Adafruit GFX Library
2. Testing with re-write OLED Display ESP8266 Examples: ssd1306_128x64_i2c

Try to run this example will fail if using ESP01, need to be change:
2.1 Reset change to -1
#define OLED_RESET -1 //Reset pint # (or -1 if sharing Arduino reset pin)

2.2 OLED address change from 0x3D to 0x3C (default is 0x3D for 128x64, but trial that it is 3C for my board.

2.3 Add wire.pins(0,2) in setup due the the OLED SDA and SCL are connected to ESP01 pin 0, 2
void setup() {
    Serial.begin(115200);
    Wire.pins(0, 2);
    Wire.begin();
    .
    .
    .

Now the example can be run fine.



Friday, May 29, 2020

Jetson Nano boot from USB

Follow "rootOnUSB" step by step, detail can find in here and here:


  1. Install your USB SSD drive in USB port
  2. Format if new drive: At Jetson nano desktop, use "search" app, search and run "Disk"
  3. Confirm USB disk drive = /dev/sda1, create and format partition in type of ext4.
  4. Reboot and check mount of /dev/sda1 from terminal: $df -h 
  5. Download from terminal:$git clone https://github.com/JetsonHacksNano/rootOnUSB
  6. $cd rootOnUSB
  7. $./addUSBToInitramfs.sh
  8. Ignore error, run:$ ./copyRootToUSB.sh -p /dev/sda1
  9. Get your disk UUID: $ ./diskUUID.sh
  10. copy text in terminal: "root=UUID=00000000-0000-0000-0000-000000000000 rootwait rootfstype=ext4"
  11. $cd /boot/extlinux/
  12. $sudo nano extlinux.conf , edit from this:
TIMEOUT 30
DEFAULT primary

MENU TITLE L4T boot options

LABEL primary
     MENU LABEL primary kernel
     LINUX /boot/Image
     INITRD /boot/initrd
     APPEND ${cbootargs} quiet

to this (the text root=UUID... is copy from step 10):

TIMEOUT 30
DEFAULT primary

MENU TITLE L4T boot options

LABEL primary
      MENU LABEL primary kernel
      LINUX /boot/Image
      INITRD /boot/initrd-xusb.img
      APPEND ${cbootargs} root=UUID=00000000-0000-0000-0000-000000000000 rootwait        rootfstype=ext4

LABEL sdcard
      MENU LABEL primary kernel
      LINUX /boot/Image
      INITRD /boot/initrd
      APPEND ${cbootargs} quiet

Reboot and finished, all data now transferred from SD card to USB SSD.



Monday, May 25, 2020

ESP01 - X-plane data

A trial parser code in Arduino decode X-Plane UDP data-gram, a sample data array assigned for trial:

In the Sample, data of the output Packet: Pitch, roll, heading:
pitch, deg The aircraft’s pitch, measured in body-axis Euler angles.
roll, deg The aircraft’s roll, measured in body-axis Euler angles.
hding, true The aircraft’s true heading, measured in body-axis Euler angles.
hding, mag The aircraft’s magnetic heading, in degrees.

The UDP data-gram sample, 41 byte:
444154412A11000000DC5C7E3F285277BED1DFCB415862E3410C0790400C079C400C079C400C07914

444154412A11 = DATA*(tab)
000000 = Index
Data 8*4byte
DC5C7E3F:285277BE
D1DFCB41:5862E341
00C079C4:00C079C4
00C079C4:00C079C4


The meaning of test data-gram in index number:
Head=0-5, index=6-8, pitch=9-12, roll=13-16, true=17-20, mag=21-24, null=25-40

Swap endiannes Hex to floating point:
DC5C7E3F => 3F7E5CDC =    0.993604 pitch
285277BE => BE775228 =   -0.241524 roll
D1DFCB41 => 41CBDFD1 =   25.4843 heading(true)
5862E341 => 41E36258 =   28.423 heading(magnetic)
00C079C4 => C479C000 = -999
00C079C4 => C479C000 = -999
00C079C4 => C479C000 = -999
00C079C4 => C479C000 = -999

float to Hex calculation: https://gregstoll.com/~gregstoll/floattohex/

_____________________________________________________________________

Arduino Program:

// Demo to decode the X-Plane UDP data packet from swap endianness HEX to 32bit floting point convertion.

char testdata[] = {
      0x44, 0x41, 0x54, 0x41, 0x2A, 0x11, 0x00, 0x00, 0x01,
      0xDC, 0x5C, 0x7E, 0x3F,
      0x28, 0x52, 0x77, 0xBE,
      0xD1, 0xDF, 0xCB, 0x41,
      0x58, 0x62, 0xE3, 0x41,
      0x00, 0xC0, 0x79, 0xC4,
      0x00, 0xC0, 0x79, 0xC4,
      0x00, 0xC0, 0x79, 0xC4,
      0x00, 0xC0, 0x79, 0xC4,
    };

long t;
int packet_index;
int x;
const char* head = "DATA*";

void setup() {
  Serial.begin(115200);
}

void loop() {
       Serial.printf("\nUDP packet contents:\n");
       // data-gram header text = DATA*
       for (int idx = 0; idx <= sizeof(head) ; idx++)
       {
        Serial.print(testdata[idx]);
       }
       // data-gram idx:
       packet_index = (testdata[6]<<16)+(testdata[7]<<8)+(testdata[8]);
       Serial.println(packet_index);

       // Only 8 data in one packet, idx will start at
       // 1=idx(9), 2=idx(13), 3=17, 4=21, 5=25, 6=29, 7=33, 8=37.
       for (int idx = 9; idx <41 ; idx = idx + 4)
       {
        // swap endiness hex to floting point convertion.
       t = (testdata[idx+3]<<24)+(testdata[idx+2]<<16)+(testdata[idx+1]<<8)+(testdata[idx]);
       Serial.println(*(float*) &t, 6);       
       }

      // below just display the original data-gram from UDP packet.
      Serial.println("UDP original Data-gram:");
         for (int idx = 0; idx < sizeof(testdata) ; idx++)
      {
          if (idx <= 8){
            Serial.print(testdata[idx]);
          }
          else {
            if (idx == 9) Serial.print("\n");
            if (testdata[idx]<15) Serial.print("0");
            Serial.print(testdata[idx], HEX);
            x += 1;
            if (x == 4 || x == 8 || x == 12)Serial.print(":");
            else if (x == 16){
              Serial.print("\n");
              x = 0;
            }
          }
      }
  delay(5000);
}

Sunday, May 24, 2020

ESP01 listening X-Plane UDP datagam

A project to show a small LCD display some fight data (e.g. compress) by individual tiny device.Aafter searching internal, I decise to usr ESP01+TFT LCD in this application.

Component list:
  • ESP01
  • 0.9 inch TFT LCD display.
  • ESP01 programmer (actually is just a USB-serial board)
1 - Add a board into the Arduino board Manager:
Copy  text:
"http://arduino.esp8266.com/stable/package_esp8266com_index.json" in to Arduino/File/Preferences/Settings/Additional Boards Manager URLs.

2 - In Arduino/Tools/Board: Select board:
 "Generic ESP8266 Module".

3 - Change the Builtin LED: from 2 to 1, (of course I has tested in example project "Blink" into my module to find out which number this board has used, which is 0,1 or 2)I
4 - Flash size change to 1M(512Kb). If upload project, the Arduino IDE will show the "Auto-detected Flash size".

5 - This now ready to test the Hello world to check the ESP01 connection and functionality,  e.g. examples included "Blink", "Hello Server" etc.

6 - Refer with UDP examples project "https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html", a little bit modified:

-------------------------------------------------------------------------------
#include
#include

const char* ssid = "ssid";
const char* password = "password";
const int packetLen = 3000;


WiFiUDP Udp;
unsigned int localUdpPort = 49000;  // local port to listen on
char incomingPacket[packetLen];  // buffer for incoming packets

void setup()
{
  Serial.begin(115200);
  Serial.println();

  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println(" connected");

  Udp.begin(localUdpPort);
  Serial.printf("Now listening at IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
}


void loop()
{
  int packetSize = Udp.parsePacket();
  if (packetSize)
  {
    // receive incoming UDP packets
    Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
    int len = Udp.read(incomingPacket, packetLen);
    if (len > 0)
    {
      Serial.printf("\nUDP packet contents:\n");
      byte x = 0;
//       for (int idx = 0; idx < sizeof(incomingPacket) / sizeof(incomingPacket[0]); idx++)
         for (int idx = 0; idx < packetSize ; idx++)
      {
          if (idx <= 8) Serial.print(incomingPacket[idx]);
          else {
            if (idx == 9) Serial.print("\n");
            if (incomingPacket[idx]<15 p="" serial.print="">            Serial.print(incomingPacket[idx], HEX);
            x += 1;
            if (x == 8)Serial.print(":");
            else if (x == 16){
              Serial.print("\n");
              x = 0;
            }
          }
      }
     incomingPacket[len] = 0;
    }
    Serial.printf("\n");
    Udp.endPacket();
  }
}
----------------------------------------------

7 - Open Arduino Serial Monitor, Start your ESP01, check is it connected, listening; and write down your ESP01 IP address.
8 - Run X-Plane, goto config and add a external monitor with your ESP01/IP address and the Port number. In this example, the port number is 4210. Maybe it's change to X-plane default number will be batter.
9 - Now the Arduino Serial Monitor will show receive the X-Plane UDP data.