Hi,
I have a two-part question if I may.
Although I have a very long experience in computing and Web programming etc., this is my first foray in snazzy LED strips and Arduino a- and C++.
Currently I have a project working from breadboard… my “trainer wheels” learner exercise.
a. driving two analogue LED strips from an Arduino Mega - using six PWM’s
b. driving one ws2812B strip (just 60 LEDS) from an arduino UNO
– Currently both boards have separate 5v / 2A PSU’s
Both Arduinos are currently external to the box, joined via breadboard jumpers etc.
Eventually, it will all be mounted in an “aluminium boxed frame” on four layers of A4 acrylic. With externally mounted jack for input power… and just one Arduino.
– I have very small tolerance vertically, but have a half-sized Adafruit Perma-Proto board mounted horizontally under one of the A4 sheets "hanging from small plastic standoffs.
What I need now is to get it all working from a single Arduino Nano (or other).
So, to my questions:
Is it possible to code for both analogue and digital strip from a single sketch?
– Any hints (rough pointers for a starting point) or links would be appreciated - I have searched but cannot find a solution.
How do you mount a Nano (or similar) on a perf board? I looked for a Tute here on Core-E but no luck so far.
– Should I use header pins for soldering and trim the pins
– Should I get a bare Nano and solder directly to some other header already mounted on perf board.
I have a tiny little JST socket (from Core-E) for the perf board to bring in the 5v.
When I get this sorted out, I will rebuild my home-hacked box into laser cut acrylic frame instead of aluminium.
You can directly solder the Nano’s pins to your perfboard
You could use a socket (if you have the vertical clearance) - I have used IC sockets. For the Nano you would need a 32-pin IC socket, but this has the advantage of being able to remove the Nano if you need to.
You could also consider using a Pro Mini (shorter than a Nano, but just as capable)
You can easily drive analog and digital LEDs together. Can you share your code? It would be easier to give an example of how to combine them if I had an idea of what you are trying to do.
Please format your code using the </> button in the forum so you keep you indentations.
Your idea of a 32-pin IC socket is appealing…
– I will, I think need to look for (or make, a couple of 4mm standoffs. Currently 6mm standoff is OK, but 6mm is not - with blank perfboard in place.
– I don’t know what space I will need for a socket.
Are there any downsides to soldering a Nano directly to a perfboard?
– Heat etc.
I did get a Pro Mini, but then found I did not have 6 PWM’s.
– Or maybe I just got it wrong.
Build my own Nano is not on the radar at this stage.
Basically, code wise, I’m just messing with existing examples at present.
– For the ws2812B strip, I’m currently just using the standard “strandtest” adjusted only for 52 LED’s.
For the two analogue strips, I’m simply (for now) just doing this:
// color swirl! connect an RGB LED to the PWM pins as indicated
// in the #defines
// public domain, enjoy!
// Varied slightly by ChrisM for two strips - Nov. 2018
// Setup for Arduino mega 2560 (PWM pinouts)
// two sets of PWM LEDS
// suffix '_set1' controlled by [loop_1]
// suffix '_set2' controlled by [loop_2]
#define REDPIN_set1 10
#define GREENPIN_set1 9
#define BLUEPIN_set1 11
#define REDPIN_set2 4
#define GREENPIN_set2 3
#define BLUEPIN_set2 5
#define FADESPEED_set1 5 // make this higher to slow down
#define FADESPEED_set2 10 // make this higher to slow down
void setup() {
pinMode(REDPIN_set1, OUTPUT);
pinMode(GREENPIN_set1, OUTPUT);
pinMode(BLUEPIN_set1, OUTPUT);
pinMode(REDPIN_set2, OUTPUT);
pinMode(GREENPIN_set2, OUTPUT);
pinMode(BLUEPIN_set2, OUTPUT);
}
void loop() {
int r, g, b;
r = 0;
g = 0;
b = 0;
while (g < 256) {
// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN_set1, r);
delay(FADESPEED_set1);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN_set1, b);
delay(FADESPEED_set1);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN_set1, g);
delay(FADESPEED_set1);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN_set1, r);
delay(FADESPEED_set1);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN_set1, b);
delay(FADESPEED_set1);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN_set1, g);
delay(FADESPEED_set1);
}
// end FADESPEED_set1
// REDPIN_set2 == 10;
if (REDPIN_set2 < 256) {
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN_set2, g);
delay(FADESPEED_set2);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN_set2, b);
delay(FADESPEED_set2);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN_set2, r);
delay(FADESPEED_set2);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN_set2, g);
delay(FADESPEED_set2);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN_set2, b);
delay(FADESPEED_set2);
}
// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN_set2, r);
delay(FADESPEED_set2);
}
// end FADESPEED_set1
}
}
// end control loop
}
As @Stephen said, the only downside is the Nano will be permanently a part of the board once it is soldered.
The Pro Mini should have the same number of PWM pins as the Nano - 6 in total. The only real different between the two boards is the Nano has 8 analog inputs where the Pro Mini only has 6 analog inputs.
As for building your own, it is surprisingly simple, and can help save space when board real estate is at a premium.
Do you happen to know the height of your:
40 Pin ZIF DIP IC Socket || #### SKU: 001-ZIF40
and
I take it that 0.6" refers to height for:
DIP Sockets Solder Tail - 40-Pin 0.6" || SKU: PRT-07944
But, are the pin sockets right for a Nano?
If poss, I would like to use Core-E for supplies, you guys have been OUTSTANDINGLY efficient with deliveries.
You can simply plug the Nano (with headers) into the perfboard and solder the header pins in place. Then trim the pins and you are done. ;^)
The ZIF socket body is 0.6" high - about 15mm. Then you’ll have the Nano sitting on that, taking up another 7-8mm. Personally I would go with a plain old DIP socket, much lower profile (and cheaper!) but I don’t think Core stock 32 pin sockets. You might get away with their 40-pin socket which should be the right width for the Nano. Alternatively, you could use Female Headers (like this 40-pin one - just cut it down to size).
You will just need to incorporate both digital and analog commands into the same “for” loops. So each step of change that is made effects both strips. It will definitely be a bit of a programming challenge to get them working simultaneously.