Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traffic Light Ws2812b LED #21

Open
TryBreakFixAgain opened this issue Mar 25, 2024 · 9 comments
Open

Traffic Light Ws2812b LED #21

TryBreakFixAgain opened this issue Mar 25, 2024 · 9 comments
Labels
build-tips Q&A about building the board enhancement New feature or request

Comments

@TryBreakFixAgain
Copy link

Would it be possible to integrate a single Neopixel or Ws2812b control to make it easier to read for older or less tech. people?

I am thinking of:
Off = nothing connected
Blue = Something connected
Green = everything ok
Yellow = Attention
Red = something bad found

@TryBreakFixAgain TryBreakFixAgain changed the title Ampel anzeige Ws2812b LED Traffic Light Ws2812b LED Mar 25, 2024
@cecio cecio added the enhancement New feature or request label Mar 25, 2024
@cecio
Copy link
Owner

cecio commented Mar 25, 2024

Hey, thanks for your input.

Your idea is for sure interesting, and not to difficult to implement from a SW point of view. May be for HW is a bit more difficult: adding a Neopixel is going to complicate the DIY build.
I'm wondering to keep your idea for the pre-built board.
Anyway, thanks again for the idea. I'll try to integrate this somehow.

@TryBreakFixAgain
Copy link
Author

the hardware side should be less of a problem, 5v, gnd and one gpio. Single LED are now quite easy and cheap to get, I've tinkered with them a bit, but the system freezes when I try to control the led, but I'm a complete beginner when it comes to programming and not skilled enough to debug it

Great project

@cecio
Copy link
Owner

cecio commented Mar 27, 2024

I think I can add something by using the on-board LED of the standard Pico board:

SOLID GREEN = All OK (which is ON by default at starup)
OFF = a warning message has been displayed (something with [!] or [!!])

@TryBreakFixAgain
Copy link
Author

I tinkered a bit and found a quick and dirty solution based on NeoPixelConnect.

https://github.com/MrYsLab/NeoPixelConnect

My code is totally experimental and not professional, I don't know if it affects other functions. according to my tests everything seems to work so far.
I would be pleased if you could check whether my code affects the function. Or you might even see a possibility to include an improved version of my code in your project. I would provide a modified PCB and a case design if my code does not affect the functions.

I have used a single WS2812B.
PIN36 (3V3) of Pi -> VCC
PIN38 (GND) of Pi -> GND
PIN14 of Pi -> Din
Yes I have only tapped the 3V3 instead of the 5V but it is enough to power the LED.

In order not to contaminate the whole code, I only modified the printout(), which is not so nice, but quick and dirty.

Initialization

//START TryBreakFixAgain TrafficLight initialization
#include <NeoPixelConnect.h>
#define PixelPin        10 // PixelData Pin
#define PixelNum 1 // Pixel count
NeoPixelConnect pixels(PixelPin, PixelNum, pio0, 1);
//END TryBreakFixAgain TrafficLight initialization

modified printout()

void printout(const char *str)
{
  display.print(str);
  // START TryBreakFixAgain TrafficLight
  String tlString = String(str);
  tlString.replace(String(char(10)), "");
  tlString.trim();
  if (tlString.substring(0,3) == "[+] ") {
    pixels.neoPixelFill(255, 255, 0, true);
  }
  else if (tlString.substring(0,3) == "[++") {
    pixels.neoPixelFill(0, 255, 0, true);
  }
  else if (tlString.substring(0,3) == "[!]") {
    pixels.neoPixelFill(255, 153, 51, true);
  }
  else if (tlString.substring(0,3) == "[!!") {
    pixels.neoPixelFill(255, 0, 0, true);
  }
  else {
    pixels.neoPixelFill(0, 0, 0, true);
    pixels.neoPixelClear(true);
  }
  // END TryBreakFixAgain TrafficLight 
}

@cecio
Copy link
Owner

cecio commented Mar 28, 2024

Thanks for your proposal.

I think your code is good, but it can be simpler in our case. It should work fine (I didn't tried it), but instead of using strings function to check the printout buffer it should be enough to check the booleans used to report anomalies:

boolean readme = false;
boolean autorun = false;
boolean written = false;
boolean deleted = false;
boolean written_reported = false;
boolean deleted_reported = false;
boolean hid_sent = false;
boolean hid_reported = false;

Also, the logic you are using is a bit strange: you are setting yellow for [+] messages, but that mean that yellow will be always set, since the selftest is printed with [+]. I would review it a bit.

I'm not sure I'm going to add this to the main branch, since I'd like to keep the HW build as simple as possible (and as I said I'll add something with the on-board led), but if you are going to work on it and create PCB and other things, I can create a dedicated branch for it, if you wish.

@TryBreakFixAgain
Copy link
Author

thank you very much, i am new to coding, i belong more to the 3d printing and soldering section.
i think it's very cool that you want to keep everything as simple as possible.

i'll keep tinkering with the idea for myself, it's a good opportunity to learn.

if it ever works exactly the way i want it to, i will let you know and of course make it available to everyone.

Thank you very much for your help and suggestions.

@cecio
Copy link
Owner

cecio commented Mar 29, 2024

Thanks to you!!
And if you have any question, just get in touch.

@TryBreakFixAgain
Copy link
Author

TryBreakFixAgain commented Apr 11, 2024

I have taken the liberty to customize the code a bit to suit my needs,

I made all display output quickly configurable with json as I see the use of other languages in my environment.

On top of that I have built a traffic light system.
I am using a Ws2812b DOT (https://www.amazon.com/dp/B088K8DVMQ) on pin 10 (GPIO7).

Blue=something is plugged in , Green= all fine , Orange=caution, Red=bad things happen

All changes are documented in the code and can be found via TryBreakFixAgain and tbfa_.

I use ArduinoJson 7.0.4 from Benoit Blanchon
I decided to use the lib and json because I have future changes in mind that I want to make.
Since I am not a programmer, I declare the code as experimental.

Of course I make the idea and my changes available for adoption into the main code and for general use.

USBvalveLanguageLightMod.txt

@cecio
Copy link
Owner

cecio commented Apr 11, 2024

Thanks a lot for sharing your work!

As I anticipated, I'd like to keep the build as simple as possible, so I'm happy to keep your mods here if someone wants to use them, but I'd like just to make a super simple mods on the main code to use the on-board led.

Thanks again for sharing this!

@cecio cecio added the build-tips Q&A about building the board label Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-tips Q&A about building the board enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants