Show Posts
Pages: 1 [2] 3 4 ... 36
16  Using Arduino / Networking, Protocols, and Devices / I2C bus running at 100kHz and 400kHz at same time? on: August 25, 2014, 08:27:17 pm
I have a Leonardo connected to Adafruit 128x32 OLED display and it's working fine. I wanted to look at the I2C SCL line on my scope and I noticed the bus speed appears to be jumping between 100khz and 400khz. Here's a video of my scope: https://www.youtube.com/watch?v=S--5ZlCXJ4M
Is it really going back and forth between the two bus speeds?  That doesn't make any sense, but I don't know what else to make of the scope output.  Here's my sketch:
Code:
#include <Wire.h>
#include <Adafruit_GFX.h>     // http://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h> // http://github.com/adafruit/Adafruit_SSD1306

#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_RESET);


#if (SSD1306_LCDHEIGHT != 32)
 #error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

void setup()  {               
  Serial.begin(9600);
  delay(4000);
 
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)

  display.clearDisplay(); 
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("HELLO THERE");
  display.setCursor(0,9);
  display.println("HAVE A NICE DAY");
  display.setTextSize(2);
  display.setCursor(0,18);
  display.println("more stuff");
  display.display();
  delay(4000);
  pinMode(13, OUTPUT);
}

void loop()  {
  display.clearDisplay();   // clears the screen and buffer
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("TIME TIME TIME TIME");
  display.setTextSize(2);
  display.setCursor(0,18);
  char buff[12];
  display.println(ltoa(millis()/100, buff, 10));
  display.display();
 
  Serial.println(millis());

  digitalWrite(13, HIGH);
  delay(100);
  digitalWrite(13, LOW);
  delay(50);   
}
17  Using Arduino / General Electronics / Re: Sketch freezes when I touch copper pour on: August 23, 2014, 01:33:22 pm
The Level shifter (PCA9306) is needed because the panStamp I'm using is a 3.3 volt board - not shown in picture form O.P.  The reason I built this test board was to experemint with the I2C pullups - both on the 5v signals and 3.3 volt signals.  The OLED display, which is on the 5v I2C line, has 10k pullups to 3.3 volts.  The 3.3 volts comes from an on-board voltage regulator on the OLED PCB.  The Real Time Clock (not shown in OP pictures) is also on the 5v I2C lines,  and it has 2.2k pull-up resistors to the 5 volt line. 

I have spots on my homemade PCB for pull-ups to 5v and spots for pull-ups to 3.3 volts (other side of PCA9306). I might not need any of them, not sure yet.  According to the PCA9306 Data sheet (Table 13), I don't need pull-ups on the 3.3 volt side - assuming I'm reading it right.
18  Using Arduino / General Electronics / Re: Sketch freezes when I touch copper pour on: August 23, 2014, 06:32:34 am
When I get PCBs made by someone like OSH Park, I frequently have a ground pour.  I made this PCB because I was just doing some tests.  I was surprised the Arduino and/or OLED display would be so sensitive to this.  I'm assuming that somehow the I2C communication is disrupted and the Arduino can't recover from that?  I've done another test where I just blink the LED on the Arduino and I can't get it to lock up by touching the copper.  I wish the I2C was more robust.  In my final design, I'll certainly have this copper grounded.
19  Using Arduino / General Electronics / Sketch freezes when I touch copper pour on: August 22, 2014, 07:31:15 pm
I've got a pretty simple sketch that using I2C to control Adafruit's OLED display.  I've got a Leonardo and the OLED display plugged into a test double sided PCB that I made.  The large copper areas on the top and bottom of the PCB are not connected to ground or anything else.  I've got 4.7k pull-ups on the I2C lines.  When I run my sketch the OLED displays some text then just counts up some numbers.  As soon as I touch the copper area the sketch freezes.  But if I ground the large copper area, the sketch does not freeze . 
I included pics of my setup.  I get the same result if I use an Uno.

Can anybody tell me what's happening?


Here's my sketch
Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_RESET);

void setup()  {               
  Serial.begin(9600);
  delay(4000);

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  // initialize with the I2C addr 0x3C (for the 128x32)

  display.clearDisplay();   // clears the screen and buffer
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("HELLO THERE");
  display.setCursor(0,9);
  display.println("HAVE A NICE DAY");
  display.setTextSize(2);
  display.setCursor(0,18);
  display.println("thanks");
  display.display();
  delay(4000);

  pinMode(13, OUTPUT);
}


void loop() {
  display.clearDisplay();   // clears the screen and buffer
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.println("TIME TIME TIME TIME");
  display.setTextSize(2);
  display.setCursor(0,18);
  char buff[12];
  display.println(ltoa(millis()/100, buff, 10));
  display.display();
   
  Serial.println(millis());
  digitalWrite(13, HIGH);
  delay(100);
  digitalWrite(13, LOW);
  delay(50);
 }


void testdrawchar(void)  {
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0,0);

  for (uint8_t i=0; i < 168; i++) {
    if (i == '\n') continue;
    display.write(i);
    if ((i > 0) && (i % 21 == 0))
      display.println();
  }   
  display.display();
}

void testscrolltext(void)  {
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(10,0);
  display.clearDisplay();
  display.println("scroll");
  display.display();
 
  display.startscrollright(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);
  display.startscrollleft(0x00, 0x0F);
  delay(2000);
  display.stopscroll();
  delay(1000);   
  display.startscrolldiagright(0x00, 0x07);
  delay(2000);
  display.startscrolldiagleft(0x00, 0x07);
  delay(2000);
  display.stopscroll();
}
20  Using Arduino / Networking, Protocols, and Devices / cloning arduino-tweet.appspot.com on: August 12, 2014, 02:53:30 pm
Success! I was able to successfully stand up an instance ( http://arduino-tweet1.appspot.com/of NeoCat's terrific Twitter proxy on Google AppEngine. If anyone is interested in setting up their own I can help with the process (and help you not repeat the many mistakes I made smiley-wink. BTW, the code, available here https://github.com/NeoCat/ArduinoTweetLib-server , is distributed under GPLv2 (http://www.gnu.org/licenses/gpl-faq.html which means you can take, modify and use it according to the normal attribution provisions (and thanks to NeoCat!).

Drew

I'm interested in cloning  arduino-tweet.appspot.com.  What tips do you have?
21  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 23, 2014, 07:01:02 pm
I had a thunderstorm come through and after looking at the graphs I realized that looking at the rain for the last 60 minutes actually was too much averaging.  I could have torrential rain for 10 minutes and no rain  for the other 50 and you wouldn't really see a huge spike.  So I decided to just track for 5 minutes, then multiply by 12 to get the hourly rate.  Here's the new code.


Code:
 static byte rainEachMinute[5];  // array holds incremental rain for a 5 minute period
  static byte minuteIndex = 0;       // index for rainEachMinute
  if ( isNewMinute() )
  {
    // Calculate new rain since since the last minute
    int newRain = 0; // incremental new rain since last minute
    if ( rainCounter < prevRainCnt )
    { newRain = (256 - prevRainCnt) + rainCounter; } // variable has rolled over
    else
    { newRain = rainCounter - prevRainCnt; }
    
    rainEachMinute[minuteIndex++] = newRain;
    if ( minuteIndex == 5 )
    { minuteIndex = 0; }
    
    // calculate hourly rain rate
    uint16_t sumRain = 0;
    for (byte i = 0; i < 5; i++)
    { sumRain += rainEachMinute[i]; }
    rainRate = sumRain * 12;
    
    prevRainCnt = rainCounter;
  }
22  Using Arduino / Networking, Protocols, and Devices / Re: Can't set static IP using WIZ811MJ Ethernet module (dynamic works) on: July 21, 2014, 08:12:50 pm
I forgot to mention.  I tried using  the same IP as the one dynamically given, and other unused IPs on the same LAN.  I've tested it in  two different locations.  There's nothing unusual about my default gateway or subnet.
23  Using Arduino / Networking, Protocols, and Devices / Can't set static IP using WIZ811MJ Ethernet module (dynamic works) on: July 21, 2014, 08:07:26 pm
I've got a WIZ811MJ Ethernet module.  I can start the Ethernet client just fine using
Code:
Ethernet.begin(mac);

But this uses a lot of memory, I want to set a static IP
Code:
Ethernet.begin(mac, ip);

But it doesn't work, I Just get back 0,0,0,0 when I print the IP address.

The WIZ811MJ is connected to a Moteino.  A Moteino is Uno compatible, ATMega328P, plus it has a transceiver radio.

Here's my test code
Code:
#include <SPI.h>
#include <Ethernet.h>  // Modified by SurferTim to allow user selectable SS pin, see bit.ly/1nvz2ye

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEC };
IPAddress ip( 192, 168,  46, 137 );

void setup() {
  Serial.begin(9600);
  Ethernet.select(9);  // Moteino radio uses D10 for SS
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());
}

void loop() { }
24  Using Arduino / Sensors / Re: Swimming Pool Water Level Sensor on: July 21, 2014, 10:19:04 am
Hello ScottG

Seems like you found an elegant solution to a problem I would like to solve. One year into it, how has your solution performed? Did you get reliable readings? How often did you end up having to change the battery?

It works great.  It's very reliable.  I think one battery will last all summer.  The battery I'm using now was installed May 28, so it's been almost 2 months.  You can see the battery voltage over time on Xively (it's channel 15).  I've got all the code on GitHub.

I did have an unusual problem the other day.  The program adds water in 15 minute increments when it senses the water level is low.  I get a text message every time this happens.  I got four text messages over an hour indicating the pool just kept adding water. I knew that wasn't right.  So I went home and discovered a chipmunk holding onto the float, trying not to drown.  The sensor just thought it was low water continuously.  That chipmunk was lucky I went home to check on things.

I need to make my code a little smarter so it waits a bit before adding water right away.  I do have a 120 minute per day max on the water fill, but I'm going to lower it to 60.  I typically only need 15 to 30 minutes a day for water.

25  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 19, 2014, 01:48:53 pm
Here's what I came up with.  I haven't tested it yet.
rainCounter is a global byte and it's basically a pulse counter from the rain gauge.  It just counts up by one every time the rain gauge measuring cups tips.  When it reaches 255, it just rolls over to zero and keeps on going.

Code:
void updateRainAccum()
{
  static uint8_t rainEachMinute[60]; // array holds incremental rain for each minute of the hour
  static uint8_t prevRainCnt = 0;    // rain count (not incremental) from previous minute
 
  if ( isNewMinute() )
  {
    DateTime now = rtc.now();
    uint8_t newMinute = now.minute();
   
    // Calculate new rain since since the last minute
    int newRain; // incremental new rain since last minute
    if ( rainCounter < prevRainCnt )
    { newRain = (256 - prevRainCnt) + rainCounter; } // counter has rolled over
    else
    { newRain = rainCounter - prevRainCnt; }
   
    // add new rain and remove rain from an hour ago
    loopData.rainRate = loopData.rainRate + newRain - rainEachMinute[newMinute];   
     
    rainEachMinute[newMinute] = newRain;  // Update array with latest rain amount
    prevRainCnt = rainCounter;
   
    // Increment daily rain counter
    loopData.dayRain += newRain;
  }

  // reset daily rain accumulation
  if ( isNewDay() );
  { loopData.dayRain = 0; }
 
} // end updateRainAccum()
26  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 17, 2014, 10:36:22 am
Yes, that's how I understood your original post. See my suggestion above.
I was looking at econjacks code and missed your post.  I like your suggestion.  I prefer to make the code more "elegant" even if I'll never notice the performance difference.  Thank you!

I'll post my code once I write it.

27  Using Arduino / Programming Questions / Re: calculate running 60 minute total on: July 17, 2014, 10:26:49 am
I'll be using the time.h library and getting the time from NTP time servers on the internet.

I don't want to reset the hourly rain to zero after an hour is over, I want to drop off any rain that's over an hour old.  For example lets say my rain came in like this (I'm skipping minutes with zero rain)

minute 1 = 0.1"
minute 2 = 0.2"
minute 3 = 0.1"
minute 55 = 0.3"

So at the end of the hour, my rain total would be all these added up = 0.7"
Assuming it's not still raining, at 1 hour and one minute, I'd drop off the 0.1" from an hour ago and my new hourly rain total would be .2 + .1 + 3. = 0.6
At 1 hour 2 minutes the hourly total would be .1 + .3 = .4"
At 1 hour and 55 minutes, I'd finally drop off all the old rain and my hourly rain total would be zero.


28  Using Arduino / Programming Questions / calculate running 60 minute total on: July 17, 2014, 08:09:34 am
I have a weather station (Davis VP2) that will send my Arduino rain data.  It comes in as one byte and just counts up to 255 then rolls over.  Each digit is 0.1 inches of rain.  I want to send the data to Weather Underground and they want it as a rolling 60 minute total.  I was thinking of creating a 60 byte array (one element for each minute).  Then looping through the array to calculate the total.  As new data comes in for a particular minute, I'd overwrite the old data for that minute.  It seems like this approach should work okay, but I was wondering if there are other ways I could do this?
29  Using Arduino / Networking, Protocols, and Devices / Re: Problems with xbee.h v0.5 [SOLVED] on: July 02, 2014, 01:05:28 pm
Okay, I figured it out.  For my sketch that's running on a Leonardo, I need to use Serial1 instead of Serial, like this:

Serial1.begin(9600);
xbee.setSerial(Serial1);
30  Using Arduino / Networking, Protocols, and Devices / Re: Problems with xbee.h v0.5 on: July 02, 2014, 12:12:28 pm
I forgot to mention, one of my Xbees is used with a Leonardo, the other with an Mega.  Since Leonardo uses serial differently, maybe this is part of the problem.  Also, I'm using the xbees in API mode.
Pages: 1 [2] 3 4 ... 36