Pages: [1]   Go Down
Author Topic: Serial.begin and current draw  (Read 525 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 31
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi All,

I just wanted to check whether I should expect current draws of around 30mA whenever using Serial.begin(115200); I have a barebones arduino setup on a breadboard that I can sleep down to 0.7mA when using a very basic sleep sketch. As soon as I add in Serial.begin I am seeing this jump up to 30mA even when sleeping. Is this normal?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 498
Posts: 19059
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post this sketch? Then we can try for ourselves.

http://www.gammon.com.au/power
Logged


Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3071
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Serial.begin() should activate the internal UART and do - among other stuff - the equivalent of
Code:
pinMode(1, OUTPUT);
digitalWrite(1, HIGH); // idle , 0 = start bit
What do you have connected there ?
How much current does this code alone invoke ?
Are you sure it sleeps, if something is connected to the Rx pin, sending data ?
Logged

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

Here is the sketch, please excuse the mess I am purely prototyping at the moment.

Some notes, I am using the breadboard setup that Nick has on his site: http://www.gammon.com.au/images/Arduino/Minimal_Arduino1.jpg with a 328P that has been re-flashed to run at 8mhz lillypad style.

The gps I am using is the adafruit ultimate gps breakout.

The code essentially runs the following:

Arduino starts up and attempts a GPS fix, which counts through to 2 minutes. If no GPS fix then the arduino sleeps into power down mode and the GPS is turned off via its enable pin. If a fix is found within the 2 minutes then the sleep is initiated earlier.

The code is:
http://pastebin.com/xpGhfYs2

I have highlighted in the code above where the command (line 74.. message length was too long for post so had to put this on pastebin) is called to start the serial (it has been uncommented along with all of the serial.print lines whilst I have been measuring current draw). With the code as above during sleep I can get 0.7mA as expected. However if I uncomment the serial.begin line and the corresponding serial.print lines later on it seems to run much higher as shown below.

The following consumption readings have been measured:
barebones as lilly running 8mhz:
arduino awake = 11.6mA
arduino sleep = 0.3mA
arduino + gps (aquiring fix) = 49 - 57mA Note: Seems quite high as GPS aquiring fix is only around 20-25mA from data sheet
arduino + gps + sleep = 37mA // figures incorrect serial.begin adds in another 20ma atleast?! GPS is definitely asleep as tested without GPS breakout on board
arduino + gps + sleep + gps disabled + no serial.begin = 0.7ma sleep and 20mA wake[/li][/list]

On the 3rd test case you can see I noted that it seems quite high consumption. I would have expected 30mA approx but something was pushing nearly another 30mA on top of this.
On the 4th test whilst everything was asleep I noticed a draw of still 37mA.. I even disconnected the GPS and still had over 30mA being pulled.
On the 5th test I commented out all of the serial.begin and print code and everything worked as I would have expted.

Conclusion was that the serial.begin was causing the issue?


Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 498
Posts: 19059
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You can attach files, you know. Not everyone wants to go to pastebin.

I'm not at my main PC right now but I think you can do a Serial.end to close the serial connection.

http://arduino.cc/en/Serial/End
Logged


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

Attached for those who do not want to use pastebin..

* GPS.ino (7.84 KB - downloaded 11 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 498
Posts: 19059
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
SIGNAL(TIMER0_COMPA_vect) {
  char c = GPS.read();
}

I wouldn't be doing serial reads inside an ISR.

Code:
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it

Surely the GPS doesn't need to be queried every mS?

Code:
      Narcoleptic.delay(sleepTime); 

I haven't used the Narcoleptic library, however in my testing I found you should be able to get sleep current down to well under one milliamp.

http://www.gammon.com.au/power

For example, this temperature/humidity logger:



http://www.gammon.com.au/forum/?id=12106

Despite the 8-digit LED display, the SD card, the sensors, etc. most of the time it uses about 7 µA when asleep.

My immediate suggestion is to make sure everything is turned off, including your use of the SoftwareSerial port. I don't know if Narcoleptic does that or not.
Logged


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

Thank you for the input Nick. I can get under 1mA when sleeping if I ditch the serial reads. It is only when using them that I get a spike, even when awake I see more current draw during serial reads than if I comment them out. I guess I will just use them for debug and then remove them anyway as they will not be needed in the final solution.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I see more current draw during serial reads than if I comment them out. I guess I will just use them for debug and then remove them anyway as they will not be needed in the final solution.
Why do you think you need to remove them? If the Arduino does not have the USB cable (supplying power) connected, then Serial.available() will never return a positive value, so you'll never call Serial.read().

If the USB cable is connected, I can't imagine why power consumption is an issue.
Logged

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

Because I will be running the project from batteries in the future..
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because I will be running the project from batteries in the future..
Very few batteries are able to send serial data. Serial.available() should be able to tell you that there is nothing to read. There will, therefore, be no need to call Serial.read().
Logged

Pages: [1]   Go Up
Jump to: