Raspberry Pi

Kobayashi

Vyemm Raider
562
1,267
Looking for some feedback with my Pi/Arduino code since I'm now stuck and can't figure out why it's not doing what I want it to do.

I'm creating a HiFi Pi/Arduino musicbox. I will be using a potentiometer to control the volume and the value of the potentiometer will also illuminate a NEOPIXEL ring as teh volume changes.

I have got the potentiometer working, I can even get the LED light to illuminate but only one LED at a time. This may work but I'm thinking it'll be too hard to see and I'll need the full LED ring to light up as the volume goes up, and goes away as volume is decreased. When I try this in the code the lights never "turn off" when volume is increased.

If someone could give me some direction I'd appreciate it.


The code below works correctly with the single LED moving the full range, this mainly works because of the "strip.clear();" line of code near the bottom. If this line of code is removed, the ring will light up as volume increases but will not go away when volume is lowered.

Feel free to test this here with the emulator, the code is already in place and ready to go.


C++:
//Notes//
//Pot Min 0  Pot Max 1023
// Expected range for raspi 0 to 255

//Libraries
#include <Adafruit_NeoPixel.h>
#define PIN 9
#define NUM_LIGHTS 24

Adafruit_NeoPixel strip(24, 9, NEO_GRB + NEO_KHZ800);


//Variables
int analogInput = A0;                                     //Input for reading Potentiometer value
int potValue = 0;
int LEDColor = 0;                                        //Value read from Potentiometer


void setup() {
    Serial.begin(9600);                                    //Setup USB Serial output
    strip.begin();                                        //Enable LED ring
    strip.show();                                        //Turns all LEDS off on LED ring

}

void loop() {

   
    potValue = analogRead(analogInput);

    potValue = map(potValue, 0, 1023, 0, 255);            // Change the range of the pot value to match the digital signal required by the RasPi

    Serial.println(potValue);                            //Display value of Potentiometer
    delay(15);                                             //Time delay for Potentiometer reading stability

    LEDColor = (potValue);                                //Convert Potentiometer value for LED control puproses

       LEDColor = map(LEDColor, 1, 255, 0, 24);         //Map the Potentiometer value to a range that matches the number of pins on the LED Ring
 

    strip.setPixelColor(LEDColor, 255);                    //Set the pixel color and change the LEDs illuminated as the volume is increased
      strip.show();
    strip.clear();



}

void println(int potValue){
    Serial.print(potValue);

}
I can't play around with the emulator at the moment, but I think your code is just addressing the one LED and then clearing things out with every loop.

I'm thinking what you want to do is add a for loop to address each LED up to that value.
 
  • 1Like
Reactions: 1 user

TJT

Mr. Poopybutthole
<Gold Donor>
40,928
102,721
The 3.5mm jack in the middle of the 3B+ is audio out. Power is the micro usb on the end. Can feed 3.3v directly into the 3.3/gnd pins on the GPIO, but i wouldn't recommend that. Bypasses a fuse. Need to have a reliable and stable 3.3v source for this to work and not let out the magic smoke. Using a Pi for a NAS can be done several different ways, but you'll be throttled below the read/write capacity of the drive so you're better off going with an actual NAS. Some NAS can sideload pihole as well from a terminal, being linux based.

Pihole works a bit differently from a browser extension adblocker like uBlock. With uBlock it basically just prevents the ads and blocked content from displaying. Pihole is your DNS so ad requests and other blocked content is never even resolved to a destination. The traffic request stops dead at the pihole so the request for an ad is not even sent outside your home network. You may never even know pages were supposed to display so much additional trash after awhile. When Hulu was new it stripped the ad breaks from the video! No interruptions! With that said, the internet is a big place and the block lists need to be updated frequently. You can add 3rd party curated lists if you wish. It can have funky effects on some pages depending how much of the content being displayed is from 3rd party site. It's not too difficult to add a site to whitelist from it's configuration webpage. I had to whitelist my health insurance provider due to the way they authentic logins, as an example. The part of the page with the login fields wouldn't display.

There's no reason to not give it a whirl. Throw an imagine on the pi, setup pihole, then set your PC's DNS to the ip of the pi and you're done. Browse normally for a few days. If it ends up fucking with your frequently visited pages then just revert your PCs DNS to automatic to go back to the way things were. If you are happy with it, configure your router and specify the pihole as your DNS to have it autoassigned to every device in your home. Fuck your smart tv wanting to phone home every 5 minutes.
TY Sir,

But why did this Pi come with a power cable into the 3.5MM jack? Like, wall outlet plugin into 3.5MM jack? Just a weird distributor?
 

Hekotat

FoH nuclear response team
12,024
11,485
I can't play around with the emulator at the moment, but I think your code is just addressing the one LED and then clearing things out with every loop.

I'm thinking what you want to do is add a for loop to address each LED up to that value.

I haven't worked on this project in awhile due to not being able to find another pi for a reasonable price. I appreciate the feedback though and when I get a pi I'll check it out.
 

Kais

<Gold Donor>
849
1,526
TY Sir,

But why did this Pi come with a power cable into the 3.5MM jack? Like, wall outlet plugin into 3.5MM jack? Just a weird distributor?
Yeah i dunno, that's pretty weird. Got a pic?
 

Asshat wormie

2023 Asshat Award Winner
<Gold Donor>
16,820
30,963
It's not a PI but it's still a microcontroller perfect for this board

 

Kobayashi

Vyemm Raider
562
1,267
It's not a PI but it's still a microcontroller perfect for this board

Anime waifu aside, this board having individual FETs on all the outputs would have saved me from getting a relay shield on a throwaway project I threw together at work. It's too bad it's sold out - I think I could have forced them to switch over to these with that justification. Also, the reviews are excellent.
 

The_Black_Log Foler

Stock Pals Senior Vice President
<Gold Donor>
43,686
40,513
It's not a PI but it's still a microcontroller perfect for this board

It’s an arduino uno running an atmega328… It’s the perfect board for the larping “embedded systems programmer.”

So yes it probably does fit this board well
 

The_Black_Log Foler

Stock Pals Senior Vice President
<Gold Donor>
43,686
40,513
Anime waifu aside, this board having individual FETs on all the outputs would have saved me from getting a relay shield on a throwaway project I threw together at work. It's too bad it's sold out - I think I could have forced them to switch over to these with that justification. Also, the reviews are excellent.
Why are you using arduino at work? 🫤
 

Kobayashi

Vyemm Raider
562
1,267
Why are you using arduino at work? 🫤
Why not? It's a cheap, plentiful, relatively versatile microcontroller/board that served the purpose I was using it for. It's not going into anything mission critical or customer facing, just test benches and proof of concept level setups.
 

The_Black_Log Foler

Stock Pals Senior Vice President
<Gold Donor>
43,686
40,513
Stm32 or bust
Why not? It's a cheap, plentiful, relatively versatile microcontroller/board that served the purpose I was using it for. It's not going into anything mission critical or customer facing, just test benches and proof of concept level setups.
just hope you’re not prototyping anything. Arduino is hoax embedded for script kiddies. Maybe look into STM’s nucleo dev boards..
 
  • 1Like
Reactions: 1 user

Kobayashi

Vyemm Raider
562
1,267
Stm32 or bust

just hope you’re not prototyping anything. Arduino is hoax embedded for script kiddies. Maybe look into STM’s nucleo dev boards..
Thanks, hadn't seen these nucleo dev boards before. Looks like the perfect replacement since I can still use the Arduino shields. I'll pick one up and see how it does. I'm not creating any code that would ever end up in a product, but I never liked coding for Arduinos anyway.
 

Intrinsic

Person of Whiteness
<Gold Donor>
14,236
11,657
Son of a bitch, I just ordered another Pi 4 last night! At least Amazon returns are easy.
 

Intrinsic

Person of Whiteness
<Gold Donor>
14,236
11,657
I had a left over Pi 3 from a few years ago that I wanted to repurpose for a Smart Mirror side project. Why? So I could make an overly complicated and ultimately useless shared family calendar and display other pieces of information. But, it seemed fun and I also want to get back in my shop and build something.

This guy was originally a RetroPi loadout, or maybe a version of some emulation tool that was before RetroPi.

The initial install was pretty easy, reformatted the card and used the Raspberry Imager tool straight from the site. Installed the default OS. Put the card back in Pi and boot up. Connect to the Pi and get in and figure out some of these commands, no idea what they mean or do other than inferring by name.

Code:
sudo apt update

It went through a few lines and said it was fine.. okay, next steps

Code:
npm install -g @senses-mirror/senses-cli

A WHOLE BUNCH of errors. Had to comb through that line by line and make sense of what it was trying to say. I saw a few lines related to node.js 12.2.2 || < 16.X.X or similar and guessed that meant whatever node.js is was not the right version. So started the hunt for how to do that. Found out there's something called node, nodejs, and npm (also from the previous command). The a whole lot of

Code:
sudo apt-get remove nodejs
sudo apt remove npm
sudo apt-get install nodejs
sudo apt-get install npm
node -v
nodejs -v

And etc and could never get it to grab anything other than a version 12. So back on the hunt for how to manually get version whatever the newest is. I have no idea what this crap is. Found another tutorial that seemed to point me in the right direction:

Code:
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs

That pops up some big warning banner about how this whole thing is deprecated and I need to look at the node website to find the new way to do this. Good lord. Back to the drawing board.

I found on the Node.js site a link to node-v18.18.0.tar.gz and then found another tutorial showing me how to use a similar process as above to grab just that file, then unzip it (or whatever) and add it. Well that didn't work either. No idea why, can't remember at this point, still trying to make heads or tails out of all this.

Eventually I did get node installed and the correct version and was able to go back and get Sense installed.

Code:
npm install -g @senses-mirror/senses-cli
senses install
sense run

Yay! I've got the program running and can see the default layout screen. Awesome. Instructions say that I can't modify my layout on the default profile so to create a new one and switch to that one. Create a new profile, switch... nothing. Switch? Press it again, nothing. Restart Pi, start over. Go back to switch profile, nothing. Nothing I could do would switch the profile and there's almost no documentation or community out there. I was pretty much stuck. No clue how to troubleshoot that.

Time to start over and switch to Magic Mirror. Reformatting SD card now b/c somewhere in this process it was completely corrupted and Pi Imager could not write to it. Going through a reformat in Disk Management to see if that fixes it, otherwise I've got a broke SD card.
 

Intrinsic

Person of Whiteness
<Gold Donor>
14,236
11,657
Finally got a clean image from Pi Imager and got back in, now time to start up Magic Mirror.

The first instructions say to install node.js and since I've already been down this rabbit hole I wanted to try doing it the way the actual site suggests.

Magic Mirror install guide:
Code:
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Node.js guide:
Code:
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg

Code:
NODE_MAJOR=20 (or whatever version 12, 16, 18)
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

Code:
sudo apt-get update
sudo apt-get install nodejs -y

well that didn't work. A bunch of errors that I'm not sure 100% how to fix

Code:
Ign:3 https://deb.nodesource.com/node_.x nodistro InRelease                     
Err:4 https://deb.nodesource.com/node_.x nodistro Release
  404  Not Found [IP: 172.67.10.205 443]
Reading package lists... Done
E: The repository 'https://deb.nodesource.com/node_.x nodistro Release' does not have a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

No idea how I got the update to go through last night... I just want to figure this part out lol

*edit: think I got it to work, the instructions on this wiki were slightly different but it looks like everything went through. They use curly brace around NODE_MAJOR whereas the other instructions did not. No idea if that was the difference or what.

Code:
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_MAJOR}.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

after

Code:
admin@raspberrypi:~ $ node -v
v18.18.0
admin@raspberrypi:~ $ nodejs -v
v18.18.0
admin@raspberrypi:~ $ npm -v
7.24.2
admin@raspberrypi:~ $

npm is still 7.24.2 which I think needed a higher version. Can't remember.
 
Last edited: