Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Networking, Protocols, and Devices / Re: synchronous master-slave communication on: March 21, 2011, 12:43:20 pm
i don't have the arduino cookbook. things are moving so fast with arduino that a book would probably get out of date pretty fast. i started working on atmega8s and my old sketches resemble my first VIC-20 BASIC programs: short and primitive.
17  Using Arduino / Networking, Protocols, and Devices / Re: synchronous master-slave communication on: March 18, 2011, 04:33:35 pm
this is in reply to nick about the use of Wire.available(). interestingly, i'd had code in there to do that but had bypassed it for some reason (i notice it's occasionally not used when communicating with certain other i2c devices when the byte count to be returned is known).  re-enabling it seems to be making my communication completely reliable.  thanks for the idea!
18  Using Arduino / Networking, Protocols, and Devices / Re: synchronous master-slave communication on: March 17, 2011, 10:43:05 am
Can you explain exactly what you mean by "synchronously" in this context? Do you mean, you ask a question and get an answer?
i mean to ask a question of a device and then stop everything while waiting for an answer (as opposed to asynchronously, where i ask a question, go on with the program, and get the answer later, perhaps as an interrupt or in some place i can poll).
What is the problem with global variables? The response is done in an interrupt handle
there's nothing wrong with it -- but initially i'd thought the onRequest handler could also read data being passed in with the request.  this does not appear to be the case. i'd found no examples of anyone using a slave to do request-response type data exchanges of the type done by, say, a 24LC512 EEPROM, and i wanted to implement it.

I have done some examples of sending/receiving data via I2C here (scroll down to "Request/response"):

nice!  i would have loved to find this example when i was working on the problem.

You shouldn't need to send things three times. Why do that?
i did it because i'd often get zero instead of the byte i'd requested. i have no idea why -- it was being flaky.  i need to investigate further. the other i2c devices on the bus all seem to work fine; it's just the slave that occasionally throws out glitch zeroes in response to queries.
19  Using Arduino / Networking, Protocols, and Devices / Re: synchronous master-slave communication on: March 16, 2011, 11:32:30 am
i don't know how to slow things down on the i2c bus -- there doesn't appear to be support in the Wire library for that.  as for the amount of code -- that's the whole system and i didn't have time to break out the parts. the slave code (slaverman.pde) is actually the most interesting, since it allows the slave to behave like any good synchronous query-and-respond i2c slave (such as the Ds1307 real time clock).
20  Using Arduino / Networking, Protocols, and Devices / Re: synchronous master-slave communication on: March 15, 2011, 12:01:56 pm
to be clear, the i2c stuff is entirely separate from the serial communications to the computer i use to program the arduinos.  basically, i have an old-school arduino setup using a max232 chip instead of the USB chip an arduino normally has (i'm not actually using an arduino board -- just the bootloader and the IDE). it's all in the basement 100 feet from my computer, so i had to use rs-232 for communication since usb range isn't very good.

down in the basement are two atmega328s connected via their i2c ports (pins 28 and 27).  the master can read and write the analog and digital pins on the slave by specifying which ones it wants. it can also read and write the slave's eeprom.  it cannot reflash the slave's firmware.  to do that i have to throw a switch that decides which atmega's serial port (pins 2 and 3) is connected to the rs-232 cable.  if you look at the source code in the link, you can see the details of the i2c communication.  as far as i know, this is the only example online of reasonably-successful synchronous query-response communication between  master and slave arduinos.

the reason it is so important to be able to query the slave from the master is that the master's code supports a sort of telnet-style interpreter to which i can send commands. these commands come to the master via rs-232 and can then be forwarded onto the slave.

as for the range of i2c communications, i've kept that bus short because it gets unreliable when it gets longer than a few feet. however, the rangefinder (which reads fuel level in an oil tank) has to be twelve feet away.  to read it, i temporarily connect a "long range i2c" cable via quad bilateral switches for just the time necessary to make the reading.  this seems to work okay.
21  Using Arduino / Networking, Protocols, and Devices / synchronous master-slave communication on: March 14, 2011, 10:10:48 pm
This is just to report my progress with getting a master Arduino to send query information to a slave Arduino, which then synchronously returns the specified data. 

 I'm using a master-slave Arduino pair (along with a real time clock, two 24LC1025 I2C EEPROMs, and a SRF08 range finder as part of a solar/boiler controller in my basement.  All of this is networked via RS-232 (not USB, since it doesn't have the range) to my laboratory computer.

A thought occurred to me about the master and slave Atmegas in the solar controller and why I was having such a difficult time making a system allowing the master to synchronously request data from the slave.  The documentation of "Wire," the library responsible for I2C communication in Atmegas, is spotty and example-free, and I've been able to find no examples online of anyone sending requests from a master  for the return of specific data from a slave.  Part of the problem I'd been having was my assumptions about how the  Wire.onRequest ( handler works.  I'd assumed that this handler could be used to retrieve data sent by the master (since other I2C devices seemed to work this way).  But it turns out that this is not the case.  To send data to a slave as part of a synchronous request followed by a returned result, the slave can only retrieve the request data using the  onReceive ( method. On the slave side, this means that the onReceive handler has to take the data passed to it, process it however it needs to be processed, and put the results into global variables that can then be queried in the onRequest handler.

I stayed up late working on this problem but wasn't having much luck solving it. This morning I got up early and continued to work on it, trying a few things that occurred to me after I'd awaken (but before I'd gotten out bed).  But no matter what I did, I couldn't make synchronous communication completely error-free, but I managed to come close by sending three copies of all the data being requested and testing to see if they all matched.  Those as frustrated by this problem as I have been are welcome to  download my code (, which includes this master-slave synchronous communication (along with many other things).
22  Development / Other Software Development / Re: an IDE supporting simultaneous windows with different connections/boards on: March 06, 2011, 04:41:02 pm
i'm running the ide version 022 in windows and board/serial settings changes made in one window always affect all the windows.
23  Development / Other Software Development / an IDE supporting simultaneous windows with different connections/boards on: March 02, 2011, 05:55:35 pm
i have several different arduinos (or arduino-like boards) connected to my computer on several different serial ports. what i would find useful is an implementation of the IDE where different windows could remember the board type and serial port independently of one another. this would allow me to have several windows up and i could reflash to the various boards from the various windows without having to keep changing the connection and board settings as i go back and forth (some are atmega168s, some are atmega 328s, and all use different serial ports). this might sound like a small thing, but in a complex setup such as i have, it makes sense for the IDE windows to remember their state. how hard would it be to hack the IDE to do this?
24  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: 328 fuses are not the same as 168 !! on: March 14, 2009, 10:56:48 am
So what fuse state should the 328 be left in after the bootloader has been uploaded?  Feel free to reply in terms of acceptable fuse setting command as it would be entered into AVRdude.

Also, what might a good fuse unlocking command (issued prior to a bootloader upload) be?  Again, feel free to give your answer as you would make it to AVRdude. I don't need an explanation of what the bits are and what they do and the history of how they have changed from Atmel processor to Atmel processor through the years, although I'm sure that is a fascinating subject.

I'm asking this because the bootloader I keep writing in AVRdude keeps getting overwritten by the Arduino IDE - and perhaps this is an IDE problem and not a fuse problem.
25  Forum 2005-2010 (read only) / Development / Re: radio frequency broadcasting on: January 11, 2007, 12:35:01 am
Good point, so yeah, 776 kHz is the ceiling. That would explain my problem with the AM radio.  Of course, it would be a square wave and not sine unless you ran it through some sort of filter.
26  Forum 2005-2010 (read only) / Development / Re: radio frequency broadcasting on: January 10, 2007, 08:15:33 pm
By successive approximation, I found that a for loop that only toggles a port pin can do 1,552,450 square waves per second, which is 3.1236 (hmm, similar to pi) times 497 KHz, the radio frequency CosineKitty picked up this signal on.  I tuned in 1550 on the dial of an AM radio and held it nearby but got nothing that changed when I reset the Atmega.
27  Forum 2005-2010 (read only) / Development / Re: radio frequency broadcasting on: January 10, 2007, 06:25:42 pm
All kinds of good ideas.  I ran an experiment with a new test algorithm that still uses longs but doesn't do anything inside the loop except toggle a digital output line.  I saved millis, went into a million-iteration loop, and then checked millis again, and had only used 644 of them.  That's a ceiling of 1.54 MHz for square waves, well within my desired range (and good enough for AM radio!).

Here's the code:

long millisAtStart=0;
long millisAtEnd=0;
long i=0;
#define BINARY(a,b,c,d,e,f,g,h) ((a)<<7|(b)<<6|(c)<<5|(d)<<4|(e)<<3|(f)<<2|(g)<<1|(h))

void setup()

void loop()
    for(i=0; i<1000000; i++)
      PORTD ^= BINARY(1,0,0,0,0,0,0,0);  

     Serial.print(" ");
     Serial.print(" ");
28  Forum 2005-2010 (read only) / Development / Re: radio frequency broadcasting on: January 10, 2007, 03:41:28 pm
I'm not near my Arduino (acutally, it's an Olimex board with an Atmega168 in a ZIF) right now but I did try ints instead of longs and saw no performance increase.  Given that millis() looks to be expensive, I will rewrite the code when I get a chance, and have it do a skad of operations and check the millis() after it and divide by the time (instead of calling millis() several times for EVERY loop).  Thanks both of you for your help.

In the end I'll probably end up using a 555 timer for my 100 KHz application, since it won't actually need any configuration.  But my first thought had been "I'll bet I can get an Atmega8 to serve as a cheap, precise arbitrary square wave generator."
29  Forum 2005-2010 (read only) / Development / Re: programming atmega168 boot with parallel prog on: October 23, 2006, 11:15:04 pm
i had similar problems a few days ago with my custom parallel port gizmo.  double check the values of your resistors and the quality of your solders.  the fact that you don't have more errors means your thing is mostly working but you might have a short or something.

are you saying  - and this isn't clear - that this same parallel port thing you made was successful a programming an atmega8 but now fails with an atmega168?
30  Forum 2005-2010 (read only) / Development / Re: Ok, on to Atmega32 on: December 03, 2006, 06:46:45 pm
Actually, a lot more i/o.  and double the flash of the atmega168 and quadruple the atmega8.   Anything with half the storage of my old commodore 64 should be able to do a lot of fun stuff.  Still, at this point in Moore's Law I don't know why Atmel can't make a processor with a megabyte of storage that fits in the Atmega8 footprint.  Imagine what that could do!
Pages: 1 [2] 3 4 ... 6