Pages: [1]   Go Down
Author Topic: 20x4 displays garbage when calling function for PWM  (Read 1322 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some quick background first,

I decided to try adding an LCD to my project that dims the LED's on my aquarium. I've been doing this using some code passed around on some forums. I'm adding various other features to this project, trying to expand it into my own controller. So far I've added temperature sensing via the DS18B20. I'm using the DS1307 for time also. I've got the RTC, DS18B20, and the LCD (Standard HD44780 from adafruit) all working fine together. They'll print what I tell them to without issue. The problem is when I call the functions that set my dimming. The information will display to the LCD and then start getting overwritten with garbage and after a few seconds the LCD will just go blank (backlight still on).

How things are connected,

I had originally used the SPI/I2C backpack from adafruit in SPI mode and had things working perfectly. However, since it required to be on the SPI pins I read that I wouldn't be able to share this with the Ethernet Shield due to the chipset not behaving properly or something, which is a big part of my future plans. Anyway, I decided to try wiring the LCD directly. Since then I've been able to print temperature and time to the LCD just fine, but I cannot call my setLed function.

The LCD is wired as follows:
K (16) to ground
A (15) to +5v
R/W (5) to ground
V0 (3) to the pot that came with the display
VDD (2) to +5v
VSS (1) to ground

RS (4) goes to pin 14 on the Arduino 2560
E (6) goes to pin 15 on the Arduino
DB4 (11) to pin 19
DB5 (12) to pin 18
DB6 (13) to pin 17
DB7 (14) to pin 16

I have tried many different variations of these pins, but everything seems to have the same result.

My led circuit is essentially a 2N2222 transistor bringing in +10v for dimming the LED drivers. The circuit is pictured below. The only difference is that I have the 10v powering the arduino through the DC connector and pull the 10v from the Vin pin for the rest of the circuit. These plug into PWM pins 3 and 4. This part works on it's own, but I'm not ruling out any details.



Here's the code I'm having trouble with. The problems begin when I call the setLed function. It analogWrite and map, to get the desired dimming. Every sketch I've loaded for doing this does it this way. From what I understand after working on this project, it's the proper way to do it anyway.

Code in second post!

analogWrite on it's own, doesn't seem to be a problem, for instance, I can do
Code:
analogWrite(4, 255)
and things will still work fine. I've tried different variations of the setLed function as I thought it might have had something to do with passing in the time, but I was wrong on that. I have some working (hello world type code) some working code that will turn the LED's on to a certain power, but with no dimming functionality. It does print the time and temp to the screen properly while turning the lights on. It was basically one of my test sketches. I can post this in another post as I've exceeded this one already.

As for libraries. When I did the SPI method with the LCD I used the one linked to from the adafruit tutorial. The modified LiquidCrystal that is. I then switched back to the one in the IDE v0022. Anyway, I hope I got all the details, and I hope this is the right place for this. I added everything I can think of as I feel like I tried quite a bit. I don't normally reach out as I can generally find out what I'm doing wrong by searching, but I'm at a loss on this one. If there's some information I didn't include, let me know and I'll add it.


Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code I'm referring to in my first post.

Code:
/*
 Arduino LED controller for reef aquariums

// paramterized LED lighting control for reef aquariums
// use a DS1307 RTC to kick off lighting schedules
//   fade up on a given slope
//         delay a set amount
//         fade back down
//   such that the photoperiod lasts the correct amount of time


//  Circuit
//
// PWM pins described below connected to dimming circuits on drivers
// ledMaster pin below connected to a 120V AC relay to turn the LED drivers on and off (optional)
// grounds from drivers connected to arduino ground
// DS1307 RTC connected via I2C
//
//
//

*/

// Pins to control LEDs. Change these if you're using different pins.
int blueLed = 3;     // LED PWM channel for blues
int whiteLed = 4;   // LED PWM channel for whites

// Set up RTC
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68

//Set up LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(14, 15, 19, 18, 17, 16);

// Set up Temp Sensor
#include <OneWire.h>
OneWire ds(22);  // on pin 22


// RTC variables
byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;

// Other variables. These control the behavior of lighting. Change these to customize behavoir
int minCounter = 0;         // counter that resets at midnight. Don't change this.
int blueStartMins = 660;    // minute to start blues. Change this to the number of minutes past
                            //    midnight you want the blues to start.
int whiteStartMins = 720;   // minute to start whites. Same as above.
int bluePhotoPeriod = 600;  // photoperiod in minutes, blues. Change this to alter the total
                            //    photoperiod for blues.
int whitePhotoPeriod = 480; // photoperiod in minutes, whites. Same as above.
int fadeDuration = 60;      // duration of the fade on and off for sunrise and sunset. Change
                            //    this to alter how long the fade lasts.
int blueMax = 255;          // max intensity for blues. Change if you want to limit max intensity.
int whiteMax = 255;         // max intensity for whites. Same as above.


/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down
void setLed(int mins,    // current time in minutes
            int ledPin,  // pin for this channel of LEDs
            int start,   // start time for this channel of LEDs
            int period,  // photoperiod for this channel of LEDs
            int fade,    // fade duration for this channel of LEDs
            int ledMax   // max value for this channel
            )  {
  if (mins <= start || mins > start + period)  {
    analogWrite(ledPin, 0);
  }
  if (mins > start && mins <= start + fade)  {
    analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  }
   if (mins > start + fade && mins <= start + period - fade)  {
    analogWrite(ledPin, ledMax);
  }
   if (mins > start + period - fade && mins <= start + period)  {
    analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  }
}

/***** RTC Functions *******/
/***************************/
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers.
void setDateDs1307(byte second,        // 0-59
                   byte minute,        // 0-59
                   byte hour,          // 1-23
                   byte dayOfWeek,     // 1-7
                   byte dayOfMonth,    // 1-28/29/30/31
                   byte month,         // 1-12
                   byte year)          // 0-99
{
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0);
   Wire.send(decToBcd(second));
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
          byte *minute,
          byte *hour,
          byte *dayOfWeek,
          byte *dayOfMonth,
          byte *month,
          byte *year)
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  *second     = bcdToDec(Wire.receive() & 0x7f);
  *minute     = bcdToDec(Wire.receive());
  *hour       = bcdToDec(Wire.receive() & 0x3f);
  *dayOfWeek  = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month      = bcdToDec(Wire.receive());
  *year       = bcdToDec(Wire.receive());
}

void TimeToLCD() {
  getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
  //Display Date
  lcd.setCursor(0,0);
  lcd.print(month, DEC);
  lcd.print("/");
  lcd.print(dayOfMonth, DEC);
  lcd.print("/");
  lcd.print(year, DEC);

  //Display Time
  /*lcd.setCursor(12,0);
  lcd.print(rtcHrs, DEC);
  lcd.print(":");
  lcd.print(rtcMins, DEC);
  lcd.print(":");
  lcd.print(second, DEC);*/
  lcd.setCursor(10,0);
  if((rtcHrs < 10 && rtcHrs > 0) || (rtcHrs > 12 && rtcHrs - 12 < 10)){
        lcd.print(" ");
        
   }
  if(rtcHrs > 12){
    lcd.print(rtcHrs - 12, DEC);
      
  }
  if(rtcHrs == 0){
  lcd.print(12, DEC);
    
  }
  if(rtcHrs > 0 && rtcHrs < 13){
    lcd.print(rtcHrs, DEC);
      
  }
  lcd.print(":");
  
  if(rtcMins < 10){
    lcd.print("0");
      
  }
  lcd.print(rtcMins, DEC);
    
  lcd.print(":");
    
  if(second < 10){
    lcd.print("0");
      
  }
  lcd.print(second, DEC);
    
  if(rtcHrs < 12 || rtcHrs == 0){
    lcd.print("AM");
      
  }
  else{
    lcd.print("PM");
      
  }

}

/***** Temperature Functions *******/
/***********************************/

float c2f(float cel) {
 return (cel * (9.0/5.0)) + (float)3200;
}

void gettemp(void){
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
  
  if ( !ds.search(addr)) {
      // Serial.print("No more addresses.\n");
      ds.reset_search();
      return;
  }

  for( i = 0; i < 8; i++) {

  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end

  //delay(1000);     // use delay if in parasite power
  // we might do a ds.depower() here, but the reset will take care of it.

  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();

  }

  LowByte = data[0];
  HighByte = data[1];
  TReading = (HighByte << 8) + LowByte;
  SignBit = TReading & 0x8000;  // test most sig bit
  if (SignBit) // negative
  {
    TReading = (TReading ^ 0xffff) + 1; // 2's comp
  }
  Tc_100 = (6 * TReading) + TReading / 4;    // multiply by (100 * 0.0625) or 6.25

  Tc_100 = c2f(Tc_100);
  
  Whole = (Tc_100 / 100);  // separate off the whole and fractional portions
  Fract = (Tc_100 % 100);
  
  //***Display Temp***//

  lcd.setCursor(0,3);
  lcd.print(Whole, DEC);
  lcd.print(".");
  if (Fract < 10)
  {
     lcd.print("0");

  }
  lcd.print(Fract, DEC);
  lcd.write(0xDF);
  lcd.print("F   ");

}

void setup()  {
  
// init I2C  
  Wire.begin();
  lcd.begin(20, 4);

}

/***** Main Loop ***********/
/***************************/
void loop()  {
  // get time from RTC and put in hrs and mins variables
  getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  minCounter = rtcHrs * 60 + rtcMins;
  
  //set LED values
  setLed(minCounter, whiteLed, whiteStartMins, whitePhotoPeriod, fadeDuration, whiteMax);
  setLed(minCounter, blueLed, blueStartMins, bluePhotoPeriod, fadeDuration, blueMax);
  
  TimeToLCD();
  gettemp();
  lcd.setCursor(16, 3);
  lcd.print(minCounter);
  // Get ready for next iteration of loop
  delay(1000);
}

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code I have working, it's my modified hello world code.

Code:


// include the library code:

#include <LiquidCrystal.h>
#include <DS1307.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 22
DS1307 rtc(20, 21);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

LiquidCrystal lcd(14, 15, 19, 18, 17, 16);

void setup() {
  // set up the LCD's number of rows and columns:
  rtc.halt(false);
  lcd.begin(20, 4);
  sensors.begin();
  rtc.setSQWRate(SQW_RATE_1);
  rtc.enableSQW(true);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  
}

void loop() {
  analogWrite(12, 255); //blue
  analogWrite(11, 255); //white
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
  lcd.setCursor(0,2);
  lcd.print(rtc.getTimeStr());
  sensors.requestTemperatures(); // Send the command to get temperatures
  lcd.setCursor(0,3);
  lcd.print(sensors.getTempFByIndex(0));

}
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Without seeing how you hooked up the circuits, I will make a guess, the LCD wires are too close to the wire that goes to the LED driver. The EM interference coming from 10V turning on and off at the PWM frequency could alter the levels of the pins going to the LCD. I used to have a slight problem of LCD printing junk and realized that I kept a halogen desk lamp too close to the LCD wire. When I turn the lamp on, I get junk on the LCD due to the starting up of the transformer inside the lamp base. Once I moved the LCD wire away from the lamp base, I stop seeing junk when I flip the lamp switch. Move it back, I see junk again when flipping the switch. If you replace the LED driver by a 10K or 20K ohm resistor, do you still see junk when you dim?

Not to advertise my product but have you seen this serial LCD keypad panel yet? Since you use mega, you have 3 additional serial lines, dead easy to hook up. The panel has a microcontroller itself and you can easily sense buttons (serial.read()) and construct complex user interfaces, with input numbers and menus.

Full size panel with 20X4:

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/item/serial-20x4-lcd-keypad-panel---phi-panel/
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That's a good idea. Unfortunately after look at it though I'm not sure that EM interference would be it. Since these lights are in use keeping my corals alive I do most of my testing at night during at time where the value should read 0. The second sketch I posted was one I used to test the 10v circuit being on full power (255) and the LCD doesn't seem to care. So it can be at 255 and not have problems, it can be at 0 and not have problems as long as I only use analogWrite(ledPin, 0) and not map. I won't rule it out thought. The drivers aren't exactly close to my working area, but I can move them further. Also, the result of what's on the screen sort of varies. In the sketches I posted I'm actually using two different methods of getting the time and temperature. I have adapted the methods I use in the second sketch to the first sketch. In that case I do just get garbage, but the screen doesn't just turn off after a few seconds. The first sketch I posted the date I have printing to (0,0) starts to get some numbers added into it, maybe a weird character, but it usually will drop out and the screen go blank after a few seconds. The sketch I'll post below doesn't go blank and has blocks going in spaces that I'm not printing to and the spaces I'm printing to has garbage scrolling through.

Here's the code with the methods of getting time and temp adapted to the code of the very first sketch I posted.
Code:
/*
 Arduino LED controller for reef aquariums

// paramterized LED lighting control for reef aquariums
// use a DS1307 RTC to kick off lighting schedules
//   fade up on a given slope
//         delay a set amount
//         fade back down
//   such that the photoperiod lasts the correct amount of time


//  Circuit
//
// PWM pins described below connected to dimming circuits on drivers
// ledMaster pin below connected to a 120V AC relay to turn the LED drivers on and off (optional)
// grounds from drivers connected to arduino ground
// DS1307 RTC connected via I2C
//
//
//

*/

// Pins to control LEDs. Change these if you're using different pins.
int blueLed = 3;     // LED PWM channel for blues
int whiteLed = 2;   // LED PWM channel for whites

// Set up RTC
//#include <Wire.h>
//#define DS1307_I2C_ADDRESS 0x68
#include <DS1307.h>
DS1307 rtc(20, 21);

//Set up LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(14, 15, 19, 18, 17, 16);

// Set up Temp Sensor
#include <OneWire.h>
#include <DallasTemperature.h>
//OneWire ds(22);  // on pin 22
#define ONE_WIRE_BUS 22
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);



// RTC variables
//byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;

// Other variables. These control the behavior of lighting. Change these to customize behavoir
int minCounter = 0;         // counter that resets at midnight. Don't change this.
int blueStartMins = 660;    // minute to start blues. Change this to the number of minutes past
                            //    midnight you want the blues to start.
int whiteStartMins = 720;   // minute to start whites. Same as above.
int bluePhotoPeriod = 600;  // photoperiod in minutes, blues. Change this to alter the total
                            //    photoperiod for blues.
int whitePhotoPeriod = 480; // photoperiod in minutes, whites. Same as above.
int fadeDuration = 60;      // duration of the fade on and off for sunrise and sunset. Change
                            //    this to alter how long the fade lasts.
int blueMax = 255;          // max intensity for blues. Change if you want to limit max intensity.
int whiteMax = 255;         // max intensity for whites. Same as above.


/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down
void setLed(int mins,    // current time in minutes
            int ledPin,  // pin for this channel of LEDs
            int start,   // start time for this channel of LEDs
            int period,  // photoperiod for this channel of LEDs
            int fade,    // fade duration for this channel of LEDs
            int ledMax   // max value for this channel
            )  {
  if (mins <= start || mins > start + period)  {
    analogWrite(ledPin, 0);
  }
  if (mins > start && mins <= start + fade)  {
    analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  }
   if (mins > start + fade && mins <= start + period - fade)  {
    analogWrite(ledPin, ledMax);
  }
   if (mins > start + period - fade && mins <= start + period)  {
    analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  }
}


void setup()  {
  
// init I2C  
  rtc.halt(false);
  lcd.begin(20, 4);
  sensors.begin();
  rtc.setSQWRate(SQW_RATE_1);
  rtc.enableSQW(true);
  

}

/***** Main Loop ***********/
/***************************/
void loop()  {
  sensors.requestTemperatures();
  // get time from RTC and put in hrs and mins variables
 // getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  Time t;
  t = rtc.getTime();
  minCounter = t.hour * 60 + t.min;
  
  //set LED values
  //setLed(minCounter, whiteLed, whiteStartMins, whitePhotoPeriod, fadeDuration, whiteMax);
  //setLed(minCounter, blueLed, blueStartMins, bluePhotoPeriod, fadeDuration, blueMax);
  
 // TimeToLCD();
 // gettemp();
  lcd.setCursor(0,0);
  lcd.print(rtc.getTimeStr());
  lcd.setCursor(0,3);
  lcd.print(sensors.getTempFByIndex(0));
  lcd.setCursor(16, 3);
  lcd.print(minCounter);
  // Get ready for next iteration of loop
  delay(1000);
}

However, I do want to add that I don't mind you advertising that product. I actually like that idea very much. I have a flexible keypad thing I just threw in the order with my LCD. I figured I'd get around to messing with it. I do need some kind of input at some point for a few things, like starting a feeding mode that turns off power heads in my tank so the fish can eat and priming for dosing pumps and such. Anyway, it would be nice to have some buttons built into the screen. I'll definitely bookmark that and I may have recommend it to some people that are following my project locally. Would certainly be easier for setting them up. I also kinda like the idea of the black on green style since I guess you still read the screen with the backlight off. This is a minor thing though. I know a lot of the people I've showed my project here to really like the white on blue. Just skimming over the features you list though, and I really do like it. The buzzer would be perfect for alarms I eventually want to set. Yea, you could say I'm very interested now. Thanks for bringing that up.
« Last Edit: September 21, 2011, 12:19:39 am by exist » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

exist,

The EM interference only occurs when you have a large current and a large change of current in time. If you write 255, then the LED is on and current to it is constant, so is when you write 0. You get interference when you do other numbers, maybe 127 being most severe. If you have the LED full on and have no problem, then turn it to half on with analogwrite of 127 value to see if the LCD spits out junk. If it does, it is definitely EM interference.

I've checked your code and didn't find much problem. This one on the other hand could be checked:
You are using the arduino mega's serial port pins 14-19 for your LCD. I don't know if that affects how the LCD communication works. Could you use other pins instead?

Thanks for liking my panel. If you want, you can get the back pack version, with everything except for the display so you can use your favorite 20X4 display. Plus the panel has 4 LED indicators, you can mark them: light, pump, something, something, so you can see the status of your system from afar, besides the buzzer can play different tone for different warnings.

http://www.inmojo.com/store/liudr-arduino-and-physics-gadgets/item/serial-20x4-lcd-keypad-panel---phi-panel/
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah ok, I understand now. I just gave it a try and with the code in the third post. I changed the pins on the LCD to 24-29. At 127 there is no garbage or glitches. I then picked up the drivers and move them closer and still no affect. I did move them further away after doing this as well and no difference. I went back and put the code in the second post on and still get the garbage.

Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So I guess the serial pins are giving you the trouble but the LED driver is not? (though I strongly suggest you wire th LED driver away from anything else). When you compile your code, the arduino automatically include hardwareserial.h, which initializes pins 14-19 to 3 set of serial ports. I guess that doesn't work so well if you want to re-purpose those pins for LCD.

Regarding the different codes, you are changing the analogwrite value in your code on post 2 but stay at a constant analogwrite value (you tried 127) in your code on post 3. I assumed you also stayed away from pins 14-19 in modified version of code on post 2.

For code on post 2, what if you disconnect the LED driver and replace it with a 10K or 20K ohm resistor and try again?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'll avoid the 14-19 for now. My last post I had changed form them anyway and still had no luck, so they may not be helping, but something's still off. Anyway, I tested using a 10k resistor, couldn't find a 20k in my stash. I disconnected my white driver attached to pin 4. I only ran the white setLed function and kept the blue commented out. Using the code in the second post, as requested. The LCD works just fine this way. I tested without the resistor and with the LED driver unplugged and again, it worked just fine. So same behavior with a 10k resistor and no connection. I'm not sure where this takes me so hopefully you can provide some insight. To me it sounds like it's something related to the LED driver, but I don't know what. I do appreciate the help. Even though it isn't solved yet, I do feel like some progress is being made, so a big thank you.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess both serial pins and LED drivers are the sources of the problem. You've eliminated one by using other pins to drive the LCD, now it's the LED driver. I will need pictures of how the wires are laid out from your arduino to the LED driver. With the test 1) 10Kohm load and 20 no load, no problem, then with test 3) with LED driver with load, problem! Your wire to the LED driver is too close to the wires to the LCD and interference was the source of problem. How long are the wires from the arduino to LED driver, and same for arduino to LCD? Without seeing your setup pictures I can only do so much smiley
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Finally had a chance to take some pictures. Pardon the dog hair. This is how I laid everything out since I started troubleshooting this. For the resistor test I put the breadboard underneath the connection between the LED dimming circuit and the driver, you'll see that labeled in the picture.

Here's the overall picture, the rest are more close up.



The breadboard with resistor went bellow this during that test.





Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

New Development!

I'm using the code I posted in post 3, that I thought was working. I just went to change the analogWrite from 255 to 0, uploaded the code, and the screen blanked out. It didn't display any wrong characters or garbage, it just turned on after the upload, and then disappeared.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So the LED wires and LCD wires are pretty much separated. So this can't be EM interference then.

Here is another theory: insufficient power.

Do you know how much current the LED drivers will take when fully on and the current rating of your ac adapter?

If you have a 10uF or even 1uF capacator, add it between 5V and gnd on the work space board to stabilize the power to the LCD.

BTW, a clear shot of the soldering job on the LCD will be a good thing to show smiley

So the LED and LCD are definitely not working together!?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hmm, you know, I had a theory about insufficient power causing a weird problem at one point when I was just running the LED's. Nothing else made sense at the time. Although the problems seemed to have stabilized it would occasionally bark up. The behavior I'm talking about was just with dimming the LED's. It seemed particularly prominent when ramping down at the end of the day. Since I have a set period of time in which the lights will start dimming from 255 and when they'd finish at 0 I was able to time it fairly well. At each "change" the light would go completely out and then back on at the correct level. Most people I see doing this on the reefer forums are using a 12v source and using a voltage regulator (have these on hand and built this circuit but never used it) to bring it down to 10v. I was wanting to back to this route as I wanted to be able to have 12v source in this whole thing for when I add fans. I also wanted a little more current on the lovely wall wart. Anyway, here's my current power supply specs. I never had anything to compare it to in terms of whether it'd be enough or not. I know it isn't regulated, so I was planning on a 12v regulated if I can find one with enough current to cover my needs.

Input Voltage (nominal): 100-240VAC
Input Current (max): 0.3A
Output Voltage: 10V
Output Current: 500mA
DC Output Connector: 2.5mm Barrel Plug
DC Output Cord Length: ~5 feet

I should have those capacitors on hand somewhere so I'll give that a shot as well. I'll double check my soldering and even pull out the macro lens to get a useful pic. It definitely appears that the LCD and LED's aren't "completely" working together, I just hadn't encountered the fault in some of the sketches I've been running. To put my power needs into perspective, I have 4 120mm 12v fans I'd like to power from this in the near future. The idea will be that they will be speed controlled by the Arduino based on the temperature of the heatsink of my LED's.  Again, thanks for the help, definitely feels like the problem is being narrowed down upon.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

exist,

500ma seems to be insufficient. I have two alternatives

1) since the problem shows up at ramping time, maybe the change of current is too much to handle. Try a large capacitor maybe 10 uf or more again between arduino vin and gnd to stabilize the wall wart output during peek changes.

2) Use a separate wall wart to power the LED driver and connect the gnd of both wall warts together. This way you won't worry about power again.
Logged


Pages: [1]   Go Up
Jump to: