Data format to control individual addressed LEDs

I have a strip of WS2812B LEDs, that are driven by an Arduino Mega, which is connected to a Raspberry Pi (and appropriate power for the length).
Using the FastLED library I can control individual LEDs -
LED[0] = CRGB (255, 0, 0);
LED[1] = CRGB (255, 255, 0);
I’m trying to create a flight tracking compass using a JSON file from Dump 1090:

{“hex”:“471f45”,“alt_baro”:16825,“alt_geom”:17000,“gs”:345.7,“ias”:282,“tas”:358,“mach”:0.580,“track”:77.1,“track_rate”:0.00,“roll”:-0.4,“mag_heading”:75.8,“baro_rate”:2560,“geom_rate”:2624,“squawk”:“0502”,“category”:“A3”,“nav_qnh”:1012.8,“nav_altitude_mcp”:23008,“lat”:54.852219,“lon”:0.512720,“nic”:8,“rc”:186,“seen_pos”:5.5,“version”:2,“nic_baro”:1,“nac_p”:9,“nac_v”:4,“sil”:3,“sil_type”:“perhour”,“mlat”:,“tisb”:,“messages”:200,“seen”:3.0,“rssi”:-5.5},

By take the receiver latitude/longitude and comparing it with aircraft latitude/longitude to get a bearing in degree - 1-360 - that responds to an LED (or LEDs) to light.

I’m just not sure where to perform the calculation - on the Arduino or other computer - and what format to present to the LEDs?
For example, a sketch similar to this - JSON Controlled LEDS - having created a new JSON file for it too read.

Who has the information about the aircraft ?
Are the LEDs in a circle ? How many ?

I would decode JSON with Python on the Raspberry Pi. There are JSON libraries for Arduino, but the Arduino Mega does not have a lot of SRAM memory.

When there are for example 16 leds in a circle, then calculating which led to turn on is just math. Many of us can help you with that.

Is the Arduino board connected via the USB cable to the Raspberry Pi, so there is serial communication ? Then you make up your own protocol. For example a command line followed by a LineFeed.

1 Like

Thanks; it was which way to start - Arduino or Pi - that was causing me the headache. Which parts to run on which device and how to get them to communicate.

The JSON is coming from the Raspberry Pi, which is running PiAware and connected via USB to the Arduino Board.

The LEDS are in a circle, and I’ve actually got 600 of them (10m at 60).
My plan had been to start with 360 LEDs, rather than muddy the question with extra math, and then do the calculations once that part worked. The final arrangement would likely be a rectangle and have different numbers of LED per side, but when I didn’t know where to start, that seemed a way off.
Thanks again for the reply.

Why two processors??

They are good at different jobs.
As Koepel said, the Arduino doesn’t have as much memory as the Pi to run calculations.
Currently I’m running a webserver on the Pi and communicate with the Arduino via a serial connection to control the LEDs.

Ultimately, I already had the Pis up and running, so was cheaper than buying a networking shield for the Arduino.

That’s okay, but it is also possible to send a NeoPixel signal from the Raspberry Pi. I read it uses DMA controlled PWM.

That’s why my go-to board is the Wemos D1 Mini, which has 4Mb of SRAM and WiFi.

4 Mb of SRAM is ARM Cortex M7 territory. Are you sure about that SRAM for the ESP8266?

You’re right, I type faster than I think.

  • Flash Memory: 4 MB
  • SRAM: 64 KB

Thanks, the Wemos D1 mini could be a good suggestion for this project.
Part of my query is about where to perform the calculations and get them to the LEDS. If I do all those on the Pi - which is also creating the JSON by tracking ADS-B signals - and transmit the data over the network, then the Pi doesn’t need to be in the same place and can be moved to a better reception point.

Thanks for that. I started by looking at the Pi route, just thought Arduino had more library examples to work with.
At the moment I’ve got some PHP that parses the JSON to give a string: LED[155]=rgb(0,0,255)
Now just need to work out how to get that to turn on the appropriate LED.

Here is an Arduino library that may do the calculation you want in the Wemos/Arduino.

Thanks for looking, though that library looks like it’s designed for building a GPS unit - like this: https://www.hackster.io/ptschulik/simple-gps-tracker-d3500e - using a GPS module, rather than calculating the space between two points, which is what I’m looking at.

I’ve got a PHP script that works out the bearing and, adding the altitude, outputs a LED number and colour:

<?php
// Fetch local data file
$json = file_get_contents('http://xxx.xxx.xxx.xxx:8080/data/aircraft.json');
$j_aircraft_data = json_decode($json,true);


// Home location and a constant
$lat_home=33.339734;
$lon_home=10.156381;
$p = 0.017453292519943295;    // Math.PI / 180

foreach ($j_aircraft_data['aircraft'] as $index=>$aircraft) {

        if (isset($aircraft['hex']) && isset($aircraft['lat']) && isset($aircra$

                $lat1=$aircraft["lat"];
                $lon1=$aircraft["lon"];
                $alt1=$aircraft["alt_baro"];
                //$lat1=50.339734;      // TEST hardcode
                //$lon1=-0.156381;


                // Bearing
                $r_lat1=deg2rad($lat1);
                $r_lon1=deg2rad($lon1);
                $r_lat_home=deg2rad($lat_home);
                $r_lon_home=deg2rad($lon_home);
                $r_dLon=$r_lon1-$r_lon_home;
                $x = cos($r_lat_home)*sin($r_lat1) - sin($r_lat_home)*cos($r_la$
                $y = sin($r_dLon) * cos($r_lat1);
                $brng=(atan2($y, $x)) / $p;     // i.e.  * 180 / PI;
                $nearest_bearing1=round(($brng + 360) % 360);

                //Altitude
                if ($alt1 >= 0 && $alt1 < 2000){
                        $col = "rgb(255,0,0)";
                 }elseif ($alt1 >= 2001 && $alt1 < 4000){
                        $col = "rgb(255,125,0)";
                }elseif ($alt1 >= 4001 && $alt1 < 6000){
                        $col = "rgb(255,215,0)";
                }elseif ($alt1 >= 6001 && $alt1 < 10000){
                        $col = "rgb(0,255,0)";
                }elseif ($alt1 >= 10001 && $alt1 < 20000){
                        $col = "rgb(0,0,255)";
                }elseif ($alt1 >= 20001 && $alt1 < 40000){
                        $col = "rgb(255,0,255)";
                }elseif ($alt1 >= 40001 && $alt1 < 60000){
                        $col = "rgb(255,255,255)";
                }

                        echo("LED[".$nearest_bearing1."]=");
                        echo $col;
                        echo "<br>";

        }       // aircraft data set
}       // Loop all aircraft entries


?>

The result is:

LED[133]=rgb(255,0,255)
LED[164]=rgb(255,0,0)

So the question is how to get that result to the LEDs, or put it in another format that would go.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.