Coding the AstroPixels

By default the AstroPixels will run standard R2 colours, with random HP lights. The code to do this is relatively simple and just a couple of dozen lines using the ReelTwo library which I talked about here.

/*****
 * 
 * Astropixels example sketch. 
 * 
 * This sketch will get the basic Astropixel setup by Darren Poulson working. Pinouts are designed
 * to be used with the Astropixel ESP32 breakout board.
 * 
 * 
 */
#include "ReelTwo.h"
#include "dome/Logics.h"
#include "dome/LogicEngineController.h"
#include "dome/HoloLights.h"
#include "dome/NeoPSI.h"
#include "i2c/I2CReceiver.h"

I2CReceiver i2cReceiver(0x0a);

AstroPixelRLD<> RLD(LogicEngineRLDDefault, 3);
AstroPixelFLD<> FLD(LogicEngineFLDDefault, 1);

AstroPixelFrontPSI<> frontPSI(LogicEngineFrontPSIDefault, 4);
AstroPixelRearPSI<> rearPSI(LogicEngineRearPSIDefault, 5);

HoloLights frontHolo(25, HoloLights::kRGB);
HoloLights rearHolo(26, HoloLights::kRGB);
HoloLights topHolo(27, HoloLights::kRGB);

void setup()
{
    REELTWO_READY();
    SetupEvent::ready();
    RLD.selectScrollTextLeft("... AstroPixels ....", LogicEngineRenderer::kBlue, 0, 15);
    FLD.selectScrollTextLeft("... R2D2 ...", LogicEngineRenderer::kRed, 0, 15);
    CommandEvent::process("HPA0026|20");
}

void loop()
{
    AnimatedEvent::process();
}

Going through it, the top lines are just including the ReelTwo library, which combines all the code from the various systems into one place.

The code between the includes and setup() routine define the hardware you have. In this case it is saying use address 0x0a for i2c communications, a couple of logics using the LogicEngine, a couple of PSIs again using the LogicEngine and three HPs using the FlthyMcNasty system.

Next comes the setup() routine. This just initialises some ReelTwo details, and scrolls some text across the front and rear logics. This is a good easy one to change for a more custom boot up process. The last line in the setup() tells all the HPs to come on for 20 seconds as a boot up test to make sure they’re all working.

Lastly, the main loop just does a call to animate all the lights.

More details about the ReelTwo library and how to use it can be found in the documentation.

If you want to experiment with the code, you can tweak some of the settings, etc. Just make sure the ReelTwo library is installed and you should then be ready to go.

This Post Has 8 Comments

  1. John

    Hi Darren.

    I bought a set of Astropixels and they are fantastic.
    Is it possible to get them to trigger any patterns from a signal from something like an Arduino?

      1. dpoulson

        The default i2c address I send them out with is 0x0a.

  2. John

    Thanks Darren. I will give a go and let you know how I get on.

  3. Jonathan Stringer

    Hi Darren,

    I love the effects of mr Astropixels!

    Is it possible to integrate them with the MarcDuino V3 boards in the same way that you would with the TeeCees?

    1. dpoulson

      Hey,

      Yep, you can send commands much like you do with the rseries and teecees. I haven’t tried it with marcduinos myself, but have swapped a set of my astropixels for a set of marcduino boards so will be doing some documentation for it at some point. You can look at the reeltwo library documentation tho for more info:

      https://reeltwo.github.io/Reeltwo/html/index.html

  4. David Bowles

    I am still working on interfacing the Astropixels with Marcduinos. If anyone has had success, I would love to ask you a few questions. I am coming up empty although I have attempted several methods.

    1. dpoulson

      Hey,

      Yeah, a few people on the Droidbuilders discord have been working on it. Specifically using the Astropixels Plus sketch. I know Mowee was working on some documentation. I was only vaguely following it for the most part as I don’t use Marcduinos in my builds.

      IIRC the AP+ code talked over serial to allow commands to trigger effects from the mp3/teecees connector on the marcduino.

      https://github.com/reeltwo/AstroPixelsPlus

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.