arduino nano´s program runs only when freshly uploaded
ey!
i think subject says all. have project working arduino nano, sd card reader (3.3v) , led strip (5v / ws2812b) runs when uploaded. when disconnect usb computer , reconnect it, wont run, , external power supply, wont run.
more weird fact have identical project arduino nano, sd card reader (5v) , led strip (12v / ws2811), works time.
ideas?
code:
i think subject says all. have project working arduino nano, sd card reader (3.3v) , led strip (5v / ws2812b) runs when uploaded. when disconnect usb computer , reconnect it, wont run, , external power supply, wont run.
more weird fact have identical project arduino nano, sd card reader (5v) , led strip (12v / ws2811), works time.
ideas?
code:
code: [select]
#include <adafruit_neopixel.h>
#include <sd.h>
#include <spi.h>
#define sdsspin 4 //arduino nano
//#define sdsspin 53 //arduino mega
int nppin = 6; //arduino nano
//int nppin = 23; //arduino mega
//int colorseq = neo_rgb;
int colorseq = neo_grb;
int bitstreamfreq = neo_khz800; //ws2812b
//int bitstreamfreq = neo_khz400; //ws2811
int g = 0;
int b = 0;
int r = 0;
#define strip_length 3
int framedelay = 10;
int brightness = 100;
byte x;
adafruit_neopixel strip = adafruit_neopixel(strip_length, nppin, colorseq + bitstreamfreq);
file datafile;
void setup() {
strip.begin();
strip.show();
setupsdcard();
}
void loop() {
sendfile("set01.bmp");
}
void setupsdcard() {
pinmode(sdsspin, output);
while (!sd.begin(sdsspin)) {
}
}
void sendfile(string filename) {
char temp[14];
filename.tochararray(temp, 14);
datafile = sd.open(temp);
if (datafile) {
readthefile();
datafile.close();
}
else {
delay(1000);
setupsdcard();
return;
}
}
/*
void clearstrip(int duration) {
int x;
(x = 0; x < strip_length; x++) {
strip.setpixelcolor(x, 0);
}
strip.show();
}
*/
uint32_t readlong() {
uint32_t retvalue;
byte incomingbyte;
incomingbyte = readbyte();
retvalue = (uint32_t)((byte)incomingbyte);
incomingbyte = readbyte();
retvalue += (uint32_t)((byte)incomingbyte) << 8;
incomingbyte = readbyte();
retvalue += (uint32_t)((byte)incomingbyte) << 16;
incomingbyte = readbyte();
retvalue += (uint32_t)((byte)incomingbyte) << 24;
return retvalue;
}
uint16_t readint() {
byte incomingbyte;
uint16_t retvalue;
incomingbyte = readbyte();
retvalue += (uint16_t)((byte)incomingbyte);
incomingbyte = readbyte();
retvalue += (uint16_t)((byte)incomingbyte) << 8;
return retvalue;
}
int readbyte() {
int retbyte = -1;
while (retbyte < 0) retbyte = datafile.read();
return retbyte;
}
void getrgbwithgamma() {
g = gamma(readbyte()) / (101 - brightness);
b = gamma(readbyte()) / (101 - brightness);
r = gamma(readbyte()) / (101 - brightness);
}
void readthefile() {
#define mybmp_bf_type 0x4d42
#define mybmp_bf_off_bits 54
#define mybmp_bi_size 40
#define mybmp_bi_rgb 0l
#define mybmp_bi_rle8 1l
#define mybmp_bi_rle4 2l
#define mybmp_bi_bitfields 3l
uint16_t bmptype = readint();
uint32_t bmpsize = readlong();
uint16_t bmpreserved1 = readint();
uint16_t bmpreserved2 = readint();
uint32_t bmpoffbits = readlong();
bmpoffbits = 54;
/* check file header */
if (bmptype != mybmp_bf_type || bmpoffbits != mybmp_bf_off_bits) {
delay(1000);
return;
}
/* read info header */
uint32_t imgsize = readlong();
uint32_t imgwidth = readlong();
uint32_t imgheight = readlong();
uint16_t imgplanes = readint();
uint16_t imgbitcount = readint();
uint32_t imgcompression = readlong();
uint32_t imgsizeimage = readlong();
uint32_t imgxpelspermeter = readlong();
uint32_t imgypelspermeter = readlong();
uint32_t imgclrused = readlong();
uint32_t imgclrimportant = readlong();
/* check info header */
if ( imgsize != mybmp_bi_size || imgwidth <= 0 ||
imgheight <= 0 || imgplanes != 1 ||
imgbitcount != 24 || imgcompression != mybmp_bi_rgb ||
imgsizeimage == 0 )
{
delay(1000);
return;
}
int displaywidth = imgwidth;
if (imgwidth > strip_length) {
displaywidth = strip_length;
}
/* compute line length */
uint32_t linelength = imgwidth * 3;
if ((linelength % 4) != 0)
linelength = (linelength / 4 + 1) * 4;
// note:
// x,r,b,g sequence below might need changed if strip displaying
// incorrect colors. strips use x,r,b,g sequence , use x,r,g,b
// change order if needed make colors correct.
(int y = imgheight; y > 0; y--) {
int bufpos = 0;
(int x = 0; x < displaywidth; x++) {
uint32_t offset = (mybmp_bf_off_bits + (((y - 1) * linelength) + (x * 3))) ;
datafile.seek(offset);
getrgbwithgamma();
strip.setpixelcolor(x, r, b, g);
}
strip.show();
delay(framedelay);
}
}
progmem const char gammatable[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4,
4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7,
7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, 10, 10, 10, 11,
11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16,
16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22,
23, 23, 24, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30,
30, 31, 32, 32, 33, 33, 34, 34, 35, 35, 36, 37, 37, 38, 38, 39,
40, 40, 41, 41, 42, 43, 43, 44, 45, 45, 46, 47, 47, 48, 49, 50,
50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 58, 58, 59, 60, 61, 62,
62, 63, 64, 65, 66, 67, 67, 68, 69, 70, 71, 72, 73, 74, 74, 75,
76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 104, 105, 106, 107, 108,
109, 110, 111, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 125, 126, 127
};
inline byte gamma(byte x) {
return pgm_read_byte(&gammatable[x]);
}
i have discovered interesting fact: if board connected computer, , arduino ide running, program wont start. if arduino ide off, program runs...
Arduino Forum > Using Arduino > Project Guidance > arduino nano´s program runs only when freshly uploaded
arduino
Comments
Post a Comment