Show Posts
Pages: [1] 2 3
1  Using Arduino / Networking, Protocols, and Devices / Tiny RTC - Battery Monitor pin - power drain on: August 16, 2013, 12:54:19 pm
I'm using one of these http://www.hobbyist.co.nz/?q=real_time_clock

When I attach the Battery Pin to an analog pin on an Uno, I can read the voltage of the battery. That's kind of cool.

The problem is, if you remove the power from the Uno, it seems like power drains from the RTC module to the Arduino, causing a significant voltage drop on the RTC device and thus 'loosing' it's time setting. (Voltage drops below 1v on the RTC device where it is normally closer to 3.3v)

I've reverted my project back to not monitoring the Battery Level, but it seems like there must be a way to do this: Allow monitoring of the battery level if and only if the Arduino has power. On power outage, prevent the battery from draining through the analog pin.

My first thoughts were to put a transistor between the pins such that the transistor was 'on' only when Arduino is powered and otherwise off.

Any other thoughts on how to handle this?
2  Using Arduino / Networking, Protocols, and Devices / Re: RTClib problems - Ethernet w/SD card + OneWire + DallasTempurature on: August 14, 2013, 07:23:53 pm
Bingo.

I had a 5V power supply into the power barrel

Bumped it to 12V and now everything seems to work. (Will drop it to a 9V as soon as I find one to lower power dissipation..)

Thanks.

If you have a moment, can you explain why this is making a difference? I'm assuming that it's because the power inverter was reducing the voltage slightly from 5 to < 5.  If you can confirm that would be great.

Thanks for your time.
3  Using Arduino / Networking, Protocols, and Devices / RTClib problems - Ethernet w/SD card + OneWire + DallasTempurature on: August 14, 2013, 05:24:48 pm
I'm using the following to build a temperature logger and, ultimately, controller.
  • Adruino UNO and software 1.0.4
  • Ethernet Shield with integrated SD card
  • Tiny RTC breakout board
  • OneWire DS18B20 temperature ICs
  • SanDisk 2GB micro SD card

To get everything running, I'm importing the following libraries.

Code:
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Fat16.h>
#include <Fat16util.h>

The Arduino reads the sensors and if the temperature has changed, it logs the time and temperature reading to the 2GB micro SD card.

The good news is that when I monitor everything via the USB serial port "Serial Monitor" everything works as expected. I can see the updates via the serial monitor, the code is successfully logging the information to the SD card, and I can poll the device over the Ethernet and retrieve the current temperatures as JSON.

Sample from data stored on the SD card when everything is working and the Arduino is tethered to my computer via a USB cable
Code:
1376477404,2013-8-14 10:50:4,77.90,76.10,75.20
1376484172,2013-8-14 12:42:52,78.80,77.00,77.00
1376484711,2013-8-14 12:51:51,78.80,77.90,77.00
1376485722,2013-8-14 13:8:42,79.70,77.90,77.00
1376489582,2013-8-14 14:13:2,80.60,78.80,78.80

Now, the problem I'm having is that when I disconnect the USB cable from the Arduino, all hell breaks loose. To start with the RTC seems to start returning a spurious result, basically, I get a unix timestamp value of '2212184785' constantly, which isn't even a legal value.

It seems like the Ethernet library, the OneWire/Dallas Tempurature libraries are working, and the SD card library is working, but for some reason the values reported by the RTC are junk.

Here's what on the SD card if I boot the code without being tethered. The Unix Timestamp (first value) and the Date/Time (second value) are completely wrong and do not change from moment to moment.
Code:
2212184785,2165-165-165 165:165:85,82.40,80.60,59.90
2212184785,2165-165-165 165:165:85,82.40,80.60,62.60
2212184785,2165-165-165 165:165:85,82.40,80.60,64.40

The JSON from the Ethernet connection also reports this incorrect time, but does export the correct temperature values. And more importantly, shows that the Ethernet Lib continues to work:
Code:
{"UTC":"2212184785","tf0":"82.40","tf1":"80.60","tf2":"62.60","avg":"75.20"}

I've tried compiling a version of the code with ALL calls to any Serial or Serial related functions commented out. This yields the same result, basically, the RTC doesn't seem to work. (It works if the USB cable is plugged in even though there's no serial connection. It doesn't work once the USB cable is untethered.)

I've got the RTC break out board plugged into the Analog Pins. A5 = SCL, A4 = SDA, A3 = HIGH = 5v power, A2 = LOW = Ground, A1 = BAT = Unused. See attached image.

Any ideas on why untethering from the USB would cause the TinyRTC breakout board and library to start returning crap values?
My suspicion is that it has something to do with the Wire Library and perhaps some interaction with the Ethernet Shield w/integrated SD card. ???

Attached is my code with all the calls to Serial stripped out.

When running the version ~with~ the Serial calls left in, I have free RAM of 563 bytes. (This is when Arduino is attached via USB to computer and all code is working correctly.)
4  Using Arduino / Installation & Troubleshooting / Re: Serial Port Already in Use errors Arduino 0023 and Arudino 1.0 on: March 04, 2012, 02:31:09 pm
Thanks. When I ran

lsof | grep usbserial

It showed nothing, so I did your /var/lock tip and that made all the difference. But I don't understand why.

Can you provide some clarity on what the /var/lock directory did, why it worked, and why it wasn't there before??
5  Using Arduino / Installation & Troubleshooting / Serial Port Already in Use errors Arduino 0023 and Arudino 1.0 on: March 04, 2012, 03:57:28 am
I'm getting Serial Port not found errors several different Duemilinove boards using Mac OS X 10.6.8

I've rebooted, nothing else is running, and I've updated the FTDI software from the manufacturers site. I've also gone all the way to shutdown and reboot. In the Tools->Serial Port menu I've got "/dev/cu.usbserial-A6008cPb" selected. I've also tried the tty version with no luck. The board is set to "Duemilinove ATmega 328" which matches both my arduinos. Neither one can be uploaded to.

processing.app.SerialException: Serial port '/dev/cu.usbserial-A6008cPb' already in use.  Try quiting any programs that may be using it.
at processing.app.Serial.<init>(Serial.java:144)

I'm getting the same errors on Arduino 0021, Arduino 0023 and Arduino 1.0

I can't figure out why it thinks the port is busy. Nothing else is running on the computer.

What other diagnostics can I run or what am I missing?

????
6  Forum 2005-2010 (read only) / Bugs & Suggestions / Application Install on Mac OSX on: December 19, 2010, 06:21:59 pm
I think Arduino should move back to a folder structure where the Libraries are external to the Macintosh application package.

While I back stuff up (fortunately), I almost alway forget that installing a new version of Arduino WIPES OUT the existing Libraries that one might have added!!

What a pain in the butt to have to redownload and reinstall libraries that get destroyed.

Fortunately for me, I had everything backed up from 0019, so I just restored it and extracted the libraries, but it sure would be nice if the main Arduino application was separate from the libraries folder.

Something like:

- Arduino (the actual application)
- Arduino Libraries (all the standard libraries plus any added by the user)

Would be a better structure to prevent this problem.

Or is it just me??  smiley
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing struct to function (again) on: October 05, 2010, 05:28:50 pm
Thanks! Works great. I think I'm starting to wrap my brain around it.
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing struct to function (again) on: October 05, 2010, 03:33:32 pm
Thanks for the quick response.

The code did not compile for me. I got the following errors:

Tried a few things to fix it but failed... ??


etch_oct05c:-1: error: variable or field 'do_something' declared void
sketch_oct05c:-1: error: 'ctlrResults_t' was not declared in this scope
sketch_oct05c:-1: error: 'r' was not declared in this scope
sketch_oct05c:0: error: expected constructor, destructor, or type conversion before 'struct'
sketch_oct05c:4: error: expected constructor, destructor, or type conversion before ';' token
sketch_oct05c:6: error: 'ctlrResults_t' does not name a type
sketch_oct05c:7: error: variable or field 'do_something' declared void
sketch_oct05c:7: error: 'ctlrResults_t' was not declared in this scope
sketch_oct05c:7: error: 'r' was not declared in this scope
sketch_oct05c.cpp: In function 'void setup()':
sketch_oct05c:10: error: 'ctlrResults' was not declared in this scope
sketch_oct05c:10: error: 'do_something' was not declared in this scope
sketch_oct05c.cpp: At global scope:
sketch_oct05c:19: error: variable or field 'do_something' declared void
sketch_oct05c:19: error: 'ctlrResults_t' was not declared in this scope
sketch_oct05c:19: error: 'r' was not declared in this scope
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Passing struct to function (again) on: October 05, 2010, 02:58:31 pm
I'm new to C structs and am having some problems with this concept. The code  examples above aren't complete enough for me to understand.

I'm trying to declare a structure that can be used to hold the results of an operation.

This code works, but it hard codes the structure into the function. I want to be able to pass multiple instances of the structure into the function via a pointer. Ideally, I'd be able to have multiple instances of my structure using something like:

MyStructureType new_struct;

And then pass that newly initialized struct to the function.


working code, but not very flexible:
Code:
struct {
  int cmd_ACK;
  String raw_result;
  int cmd_results[8];
} ctlrResults;

void setup () {
  do_something();
  Serial.begin(115200);
  Serial.print("Raw Results:");
  Serial.println(ctlrResults.raw_result);
}

void loop() {
}

void do_something() {
  ctlrResults.cmd_ACK = 1;
  ctlrResults.raw_result = "M1:323:M2:435";
  ctlrResults.cmd_results[0] = 323;
  ctlrResults.cmd_results[1] = 435;
}

The following doesn't work, but is closer conceptually to what I want to do.

Code:
struct {
  int cmd_ACK;
  String raw_result;
  int cmd_results[8];
} ctlrResults;

void setup () {
  do_something(&ctlrResults);
  Serial.begin(115200);
  Serial.print("Raw Results:");
  Serial.println(ctlrResults.raw_result);
}

void do_something(struct a* ) {
  a.cmd_ACK = 1;
  a.raw_result = "M1:323:M2:435";
  a.cmd_results[0] = 323;
  a.cmd_results[1] = 435;
}
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Counting Elements in an array passed to a function on: October 05, 2010, 12:23:45 pm
Thanks all for the clarifications. It makes more sense now... smiley
11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Counting Elements in an array passed to a function on: October 04, 2010, 07:08:27 pm
Thanks Coding Badly and SirPoonga.

In this case strlen works. I'm assuming that's specific to char strings.

I'm not a C expert, so I'm a little confused as to why strlen can determine the size of char string which is essentially an array of char, but it's not possible to determine the size of a normal array of say ints??
12  Forum 2005-2010 (read only) / Syntax & Programs / Counting Elements in an array passed to a function on: October 04, 2010, 06:44:53 pm
I'm trying to pass a string of characters to a function. I'd like that function to determine the number of characters in the string;

I can't figure out how to get the size of the array the pointer points to inside the function.

I tried dereferencing the pointer, but I seem to be counting only the first element.

Code:
void setup() {
  Serial.begin(115200);
  Serial.println("-- Start -- ");
  count_this("string of chars");
}

void loop() {

}

void count_this(char *str) {
  int size = sizeof(str)/sizeof(str[0]);  // Size = 2
  int size = sizeof(&str)/sizeof(&str[0]);  // Size = 1
  Serial.print("size = ");
  Serial.println(size);
}

Any thoughts on what I'm doing wrong?
13  Forum 2005-2010 (read only) / Syntax & Programs / Bit Flipping Nibbles and Bytes on: October 21, 2009, 09:41:52 pm
[size=12]Byte = 8 bits, Nibble = 4 bits

Some times you need to flip a byte or nibble from LSB to MSB.

For example "1100 0101" to "1010 0011"

Took me a while to find this, so I thought I'd share. Any comments or improvements welcome. (I'm not an expert coder, so I'm sure one of you wizards can polish this quite a bit.)[/size]
Code:
// send nibbleShift a decimal number
// example "nibbleShift(3)" returns '12'
// "0011" becomes "1100"
int nibbleShift(int num) {
  int var = 0;    
  int i, x, y, p;
  int s = 4;    // number of bits in 'num'. (This case a 4bit nibble)

  for (i = 0; i < (s / 2); i++) {
    // extract bit on the left, from MSB
    p = s - i - 1;
    x = num & (1 << p);
    x = x >> p;  
    // extract bit on the right, from LSB
    y = num & (1 << i);
    y = y >> i;
  
    var = var | (x << i);       // apply x
    var = var | (y << p);       // apply y
  }
  return var;
}
[size=12]To flip a whole byte, change the size of 's' to 8
Then if you input '3' you'll get '192' as the result.
"0000 0011" becomes "1100 000"

The other route with a nibble or byte flip is to do a table lookup. I'd be curious to hear what you think about which would be faster an the arduino; doing a table lookup or manually calculating it ??[/size]
14  Forum 2005-2010 (read only) / Troubleshooting / Re: Noise/Junk on Serial Port Using Hex Inverter. on: October 04, 2010, 06:02:23 pm
Thanks everyone.  Grumpy_Mike had the correct solution! Thanx for the guidance!

We already had it decoupled (thanx Coyote)

Prior to implementing the MAX702, I tried RuggedCircuits code improvements, but still ended up with the problem. The MAX702 works with with both versions of the code.

Thank you everybody. I'll post some images when I get a chance.  
15  Forum 2005-2010 (read only) / Troubleshooting / Noise/Junk on Serial Port Using Hex Inverter. on: October 04, 2010, 12:47:57 pm
We're having a problem that is driving me crazy...

We're using a Arduino Mega and it's 3 extra hardware Serial ports to communicate with  RoboteQ controllers via serial.

The way the RoboteQ works is that you send it a code like "!F" and then it echos back that command and then echos back the results.

The RoboteQ is hard wired as 8N1 115200. We can't change that.

The problem is that I'm getting 'junk' responses every 3rd or 4th command and that is seen in the form of extra or different characters at the beginning of the response from the Roboteq.

For example, if I send "!F", I might get "©~F" instead of the correct "!F". It's somewhat random,a lot of the characters are high or very low ascii, but the only ones I should get should be the expected readable ones. (except the newlines).

Command: ?FID

Should echo back:
?FID
FID = RoboteQ Firmware 1.xxx

Every 2nd to 4th time, it will do:

©ID = RoboteQ Firmware 1.xxx

or something like that.

We're using a SN74HCO4N hex inverter from Texas Instruments and have it wired to all three hardware serial inputs.

My first thought was interference, so we isolated the Mega and the Inverter from everything else, but still get the error. The weird thing is when I 'pull out' the connection between the inverter and Serial 3 on the Mega, the problem gets even worse, with almost entirely garbled responses from Roboteq !!. (Another words, when I try to JUST run serial 2 via the hex inverter, it's total crap. If I add wires for Serial 3, it gets 'better', but still has problems, it doesn't seem to care if Serial 1 is wired up or not.)

With all the wires plugged in, it seems like just the first couple of characters are incorrect. Usually not the end of the response.

We've shelled into the Roboteq directly from our computers using the same connector the Arduino is wired to run and everything is fine.

I'm running this code:
Code:
bool rx_flag = true;

void setup() {
 Serial2.begin(115200);  // RoboteQ attached to Serial 2
 Serial3.begin(115200);  // commenting out this line doesn't matter
// but unpluging the wires from hex inverter to Serial3 Rx/Tx DOES
// matter.
 Serial.begin(115200); //<- Arduino to IDE Serial Monitor.
}

void loop() {
 Serial.println("-- Starting Loop --");

 send2Ctlr("?FID");
 dump_echo();
 delay(2000);

 send2Ctlr("?F");
 dump_echo();
 delay (2000);
}

void send2Ctlr(char *cmd) {
 Serial2.flush();
// echo the command to the IDE serial monitor
 Serial.print("Tx: ");
 Serial.println (cmd);
// send the command to the RoboteQ controller
 Serial2.println (cmd);
}

// routine for echoing all characters received from RoboteQ
// back to the IDE serial monitor.
void dump_echo() {
 while (Serial2.available() == 0) {
   // wait for a byte
 }
 while (Serial2.available() > 0) {
   if (rx_flag) {
     Serial.print("Rx: ");
     rx_flag = false;
   }
   byte c = Serial2.read();
//    Serial.print("[");
   Serial.print (c);//    Serial.print("]");
   //    delay(30);
 }
 Serial.println("");

 rx_flag = true;
}
Pages: [1] 2 3