Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: How to copy a buffer into a struct? on: August 05, 2014, 06:16:34 am
Ahhh - thanks pYro_65 - I'll give that a go.
2  Using Arduino / Programming Questions / Re: How to copy a buffer into a struct? on: August 05, 2014, 06:15:34 am
The other direction happens on another Arduino (my transmitter). The same structs are defined there:

Code:
// Transmitter code:
// structs already defined in a header file; make some instances:
voltagesMessageStruct myVoltsMessage;
currentsMessageStruct myCurrentsMessage;
So, depending on what the transmitter wants to send, it just does this sort of thing:

Code:
// if it's time to send a "voltages" message:
radio.write (&myVoltsMessage, sizeof(voltagesMessageStruct)); // sizeof will always be 32 bytes by design
My problem is how to correctly and politely deal with the reception of what is now a blob of 32 bytes.

So at the receiver end, can I just do:

Code:
// if the first byte indicates it's a "volts" type message:
memcpy ( &myRXbuffer, &myVoltsMessage, 32 );
?
3  Using Arduino / Programming Questions / How to copy a buffer into a struct? on: August 05, 2014, 06:00:03 am
I'm receiving messages from an nRF24L01 into a buffer:

Code:
char myRXbuffer[33];

if (radio.available()) {
      radio.read(&myRXbuffer, 32);
      newDataFlag = true;
}

There are a few different types of message, and I use the first byte to differentiate them. I've defined my different message types as structs. Simplified, they look a bit like this:

Code:
struct voltagesMessageStruct {
  unsigned char messageType; // volts message type is 1
  unsigned char voltsMain;
  unsigned char voltsRes;
  unsigned int voltsSolar;
  // . . . continued until I've used up all 32 bytes
}

struct currentsMessageStruct {
  unsigned char messageType; // amps message type is 2
  unsigned int ampsLoad;
  unsigned char ampsSolar;
  unsigned char ampsReserve;
  // . . . continued until I've used up all 32 bytes
}

// make some instances
voltagesMessageStruct myVoltsMessage;
currentsMessageStruct myCurrentsMessage;

So I now have a 32 byte buffer, and checking, say, (myRXbuffer[0]==2) tells me it's structured like myCurrentsMessage. What syntax should I use to copy myRXbuffer into myCurrentsMessage?

Thoughts:
- I want to copy it rather than just "cast" it, so I can continue to use the buffer for further readings
- I could copy it long-hand, by going through each element of the struct and assigning the right bytes (or pairs of bytes, if the element is an int) but that requires a separate procedure for each structure, and is a pain to maintain.
4  Using Arduino / General Electronics / Re: Does it hurt to refresh [shift registers] continually? Do they wear out? on: May 28, 2014, 04:27:50 am
Thanks, Mark - as I get onto more complex projects it gets more costly to do the testing-for-change routine (not least because you have to have two copies of the display data in memory). No point in me making things more complicated than they need to be.

Thanks for the sanity check smiley

h
5  Using Arduino / General Electronics / Does it hurt to refresh [shift registers] continually? Do they wear out? on: May 28, 2014, 03:08:44 am
A simple example followed by a more complex one:

If you're driving LEDs with a shift register (eg 74xx595), is it bad practice to keep shifting the same data in all the time?

For example, say I make one of those binary clocks, with an Arduino or an ATTiny driving a shift register connected to some LEDs. The main loop of my sketch may end up executing 100s of times a second, but the display only needs to change once a second.

I normally do this sort of thing:

Code:
void loop() {
    myData = getNewData();
    if (myData != oldData) {
        // This code will only execute if
        // the data has changed:
        shiftOut (myData, blah, blah);
        // keep track of what's on the display for next time:
        oldData = myData;
    }
}

But is it necessary / beneficial in any way? This is perhaps an overly trivial example.

A better example: If I'm using several biggish LCDs - those 20 x 4 character 44780 ones - to display lots of live data that may or may not change, should I be writing code that checks if anything has changed before pushing what may be the same data out to the displays again? Is there any harm in redundantly refreshing displays with unchanging data?

There's a cost to doing selective display updates: takes more memory, more code / power to do the comparison.

I realise this is a bit esoteric (probably doesn't matter really) but I naturally veer towards over-coding even in situations where it doesn't matter. And I do over-think things.

Is there a general rule, a best practice? "Only refresh when you have to" vs. "Don't bother wasting time/memory on it, there's no need to cull redundant refreshes"?
6  Using Arduino / General Electronics / Re: Single sided PCB - joining up ground plane "islands" - best practice? on: May 17, 2014, 08:38:22 am
Thanks for the creative answers! A proper ground plane would be best, but it's not possible (or practical) for some of my circuits.

I'll stick jumpers everywhere I can.

Alternatively with single sided / SMT you want to make ground links low-inductance
if possible, so use wide 0R resistors (1210) - these are also long enough to
bridge traces so everything can be single sided with luck.

Yep - I love the 1210 size ones, cos you can jump over three tracks if you're careful:


(excuse the dodgy soldering, this is an old board and I've got a lot better since then)

Didn't think about the inductance thing, though; I'll stick with the 1210s rather than 0805s in that case.

Thanks!
7  Using Arduino / General Electronics / Re: Single sided PCB - joining up ground plane "islands" - best practice? on: May 16, 2014, 09:36:18 am
Hi CrossRoads,

You're right, this isn't the best example as the layout could be fixed easily; I'm really just trying to understand the principles. Say you've a complex design with many Ground islands that need to be connected together, is it best to bung jumpers everywhere, or should you keep a single path between islands (ie avoid making lots of ground loops).
8  Using Arduino / General Electronics / Single sided PCB - joining up ground plane "islands" - best practice? on: May 16, 2014, 09:19:42 am
I mill out my PCBs, and for simplicity I stick with surface mount components and single-sided PCB designs.

My ground pour / fill / poly often gets split up by the rest of the circuit, and I need to connect the islands together. This is what I mean:



It's not a problem, especially with those little 0-ohm resistors - I've stuck one on the left hand side.

Would it be sensible to stick one on the right, jumping over the output trace too? Kinda forms a ground loop, but I don't know if that's something to worry about at the PCB level. (This is a simple buck converter, cribbed from a datasheet, operating somewhere around 10-100kHz, if that's relevant).

I guess what I'm asking is whether it's generally a Good Idea to join ground islands up everywhere you can fit another jumper, or whether it's unnecessary.

(I'm guessing there's no huge difference between jumping a trace over the ground vs. jumping the ground over a trace. Or is there?)
9  Using Arduino / General Electronics / Will this audio input circuit affect what it's connected to? on: February 25, 2014, 04:17:30 am
I've made an audio meter with my Arduino and a sexy OLED display. The audio input is a simple circuit I found on Google:


It works really well. My question is: if I connect this circuit to the wires between my computer and my powered monitors using a simple Y-splitter cable, will my circuit affect the audio going to the speakers? I'm not worried about a little attenuation, but is there a chance this circuit will interfere with the character of the audio - the frequency response etc?
10  Using Arduino / General Electronics / Re: What happens if AREF exceeds Vcc by a tiny bit? How to raise Vcc (hack the reg)? on: October 16, 2013, 01:01:25 pm
Cool - thanks for the ideas and advice.

I think I'm going to go for a lower voltage reference and then scale my inputs down accordingly. Learnt lots, ta smiley
11  Using Arduino / General Electronics / What happens if AREF exceeds Vcc by a tiny bit? How to raise Vcc (hack the reg)? on: October 16, 2013, 11:08:38 am
If I hook a 12V supply up to my Arduino and then measure the 5V line, I get a fraction under 5V - around 4.96V. It seems to vary a little, depending on what the Arduino's doing. There aren't any huge loads; main thing is an nRF24L01+ transceiver that grabs 100mA-odd for a few milliseconds each second.

That's 1% error, though, which I want to reduce. I thought I'd hook up a precision 5V from a proper voltage reference chip (Analog Devices REF02CPZ).

Two questions:
  • given that my Arduino is powered by less than 5V, that means the AREF pin is going to be higher than Vcc - not enough (I'd think) to hurt it, but will the AREF pin be clamped down to Vcc?
  • if so, I need to bump the voltage from the Arduino's regulator by a bit. I understand you can stick a diode on the ground pin of a linear regulator to raise its output by the diode's voltage drop, so a 0.2V-drop Schottky should be enough, right?
Thoughts?

12  Using Arduino / General Electronics / Re: ADC input from +12 to -12V - internal diodes enough protection? on: October 14, 2013, 09:03:00 am
Spectacular. Thanks folks smiley
13  Using Arduino / General Electronics / ADC input from +12 to -12V - internal diodes enough protection? on: October 14, 2013, 06:48:38 am
I need to measure a voltage that may range from -12 to +12V, relative to ground.

I'm only interested in readings that are between -12V and 0V, though; if the voltage goes above 0 I don't care what the reading is.

From another thread I learnt you can measure negative voltages with a resistor divider, so this circuit:



... should let me read anything from -12V to +5V. That's all I need.

However, if the input voltage is higher than +5V, the voltage at the Arduino's input pin could go up to 7V. Do I need to protect the Arduino from this, or will its internal protection diodes be enough? We're talking about a maximum current of 0.1mA. Should I do this:



I'm guessing that if the verdict is yes to external diodes, I'll need to use Schottkys for their low voltage drop...

Thanks!  h
14  Using Arduino / General Electronics / Cheapest way to charge a 15V battery from solar panels? on: October 11, 2013, 03:44:11 am
*update* - I've found a relatively cheap DC-DC converter on eBay - 20A, variable output voltage:
http://www.ebay.co.uk/itm/181078755476
...would this be the answer to my problems?



I have 400W of nominally 12V solar panels. At peak power they present around 17V.
The panels produce enough power for our nightly needs (30Ah/day), but storage is the problem: car batteries are horribly inefficient and waste a large proportion of the juice, so I've just bought a monster 60Ah Lithium battery (LiFeYPo) to store the power.

The problem: the new battery operates between 10 and 16V; if I use my existing 12V solar charge controller the battery is never charged beyond around 13.2V, which equates to around a quarter of its capacity.

What would be my simplest approach to charge this battery from the panels? I want to charge it up to 15V ideally.

I could:
a) connect the panels straight to the battery, via a blocking diode, and an over-voltage cut off (arduino + relay)
b) use an off the shelf (ie eBay) DC-DC buck converter set at 15V. I'm not clear on what impedance this would present to the panels though: if the battery is fairly flat it'll happily absorb as much current as the converter can produce, but does that mean the converter will look to the panels as if it's nearly a short-circuit? (If so, it won't harm the panels, but they won't operate at very good efficiency)
c) buy a simple (ie analog) PWM 12V controller and try and hack it to produce 15V instead ... (I'm guessing that somewhere inside there'll be a feedback resistor I can play with)
d) keep looking for a proper solar-lithium charger (specialty item = horribly expensive)
e) build a custom PWM controller for it (bit advanced for me, especially if it's got to handle up to 30A of current)
f) stop complaining, stick with my MPPT 12V controller, live with the reduced capacity because it's still working miles more efficiently than the lead acid batteries.

Thoughts? Budget is tighter than a gnat's chuff, so hacky solutions are grand. Over- and under-voltage protection are trivial to implement (I can watch the voltage with an Arduino, cut things off with a relay in case of danger). The lithium battery is designed as a swap-in replacement for lead-acid batteries, so it's fairly resilient to abuse (as opposed to vanilla Li-Ion cells). It can handle up to 60A of charge current, way more than I could ever produce.

(Gotta say, I love this lithium battery - stick 10Ah into it and you can get 9.9Ah out of it again, as compared with lead acid, where I'd be lucky to get just half the juice out again)
15  Using Arduino / Programming Questions / Re: Storing strings of various lengths - am I doin' it right? (pointers) on: November 09, 2012, 06:58:08 am
Cool, thanks! smiley
Pages: [1] 2 3 4