Arduino stamp (mini) pinouts for i2c twi

I wasn’t sure where to put question this since it’s related to Arduino Stamp (Mini). Perhaps SparkFun moderators could make some arduino specific sections of the board where it would make more sense. I apologize if this is the wrong spot.

I’ve searched numerous forums here and at arduino and cannot find any reference for the pinout of the i2c interface on the Stamp/Mini. I’ve seen references to pins 0 and 1 on the regular arduino board, but haven’t found much on the Mini.

Also, is there a mini schematic you can point me to that will show the atmega mappings to the Mini pinouts?

Any help towards schematics and reference material is appreciated.

Thanks,

Landon

http://www.arduino.cc/en/Main/ArduinoBoardMini

and as for your two-wire interface (i2c) on the Atmel Atmega8, it’s on page 163 of the Atmega8’s datasheet, located here: http://www.atmel.com/dyn/resources/prod … oc2486.pdf

Not saying this for sure, but I’m not sure the arduino software will allow you easy access to the interface (I just don’t know, I bought an arduino board myself, but I’ve found myself using it more as just a generic programmer for the atmel chips than using the language and the interface), but you can definitely get to it from avr-libc. Google’s going to be a lot more helpful for this than I am, I’m just learning the platform myself. But, that should at least answer those big questions for you.

Thanks for you response.

I do see:

http://www.arduino.cc/en/uploads/Main/a … ematic.pdf

But interestingly it shows the ATMEGA device as an ATMEGA8-A (I assume either they meant an ATMEGA168 or 8-A is some psuedonym for a 168.)

Looks like from that schematic that SCL and SDA lines map to ADC5 and ADC4 which are not on pins - only pads. That’s fine, but does look like it’s brought out anyway.

Also I found http://research.techkwondo.com/blog/julian/259 which shows how to map the full-size arduino board to SPI, so that was helpful as well. He has some code that shows how he’s reading and writing registers in the external device. Based on those mappings, looks like everything is there on an arduino Mini stamp but just SCL and SDA are not pinned.

Is that how you see it, too, based on the schematic?

So, I’m starting in on I2C on the Arduino. I wonder if you’ve had any luck?

Sorry none. I’m not sure the Wire interface code works on the Mini - I can’t see any activity on those ports when I run it and when I do run the code with the wire interface on the mini, it seems to hang.

I’ve posted on the Arduino forum the same suspicion that the wire interface isn’t supported on the Mini and I haven’t had any confirmation or negation - it’s almost like no one’s tried it or everyone thinks it’s a stupid question, I’m not sure which.

I’m not sure where to go with it now, so I’ve let it rest for awhile. I’m still interested, though, in getting an answer.

Huh. Not sure why it wouldn’t work, but I haven’t tried either. I did manage to get it working on an Arduino (the full-sized board) without any hassle. I’ve got some documentation here:

http://research.techkwondo.com/blog/julian/279

If you have a Mini, I’d be interested in what you find using it with the same code and device described on your project page.

I may go back and try again - perhaps a fresh look will help. I’ve been trying to use Wire with the Sparkfun Realtime clock. Would like to see it work.

I started in on it again tonight and breadboarded the Arduino mini with the Arduino USB->Serial converter. I then wired up the Sparkfun Real Time Clock. I had previously soldered a two-hole female header to the ADC4/ADC5 pins on the mini and ran the RTC SDA line to ADC4 and RTC SCL to ADC5 of the mini. Of course I powered the clock as well.

I ported some code by combining Julian’s page and some of the PIC code that came with the RTC (I used that only for addresses, register numbers, and basic info on the RTC.)

The problem I’m having is identical to what I’ve seen before when I tried to do this and that is that the chip hangs in the Wire.begin().

In the case, tonight, I put a serial print before Wire.begin and one after. From the console, I only get to the one before… I see “Calling Wire.begin”, but not the print after Wire.begin.

Also of note, every few seconds, setup() gets called again - the chip must be going through a reset and I see my serial print before the Wire.begin.

I tried it with the clock disconnected from the ADC4/ADC5 lines. Same results.

I’m nearly 99% certain Wire is boned on an Arduino Mini.

You can pretty much ignore all the code I’ve written so far, though I’m posting it below, because it doesn’t ever get past the Wire.begin call from what I can tell.

#include <stdio.h>
#include <Wire.h>


// Landon Cox
// TWI (I2C) sketch to communicate with the Sparkfun RTC

// code loosely based on Julian's TWI page:
//    http://research.techkwondo.com/blog/julian/279
// and SparkFun's PIC code to get register and address values
//


#define RTCADDRESS   0x00

//Read hours register
#define RDHR        2 
//Read minutes register
#define RDMIN       1
//Read seconds register
#define RDSEC       0
//Read Day
#define RDDAY       3
//Read Date
#define RDDATE      4
//Read Month
#define RDMON       5
//Read Year
#define RDYR        6


void setup()

{
  Serial.begin(9600);
  
  Serial.println("Calling Wire.begin"); 
  Wire.begin(); // join i2c bus (address optional for master)
  Serial.println("Back from Wire.begin");
}


void loop()
{

  Serial.print("Reading clock");
  readclock();
  
  delay(2000);
}

void readclock()
{
  int hours=0, minutes=0, seconds=0;
  char timestr[30];
    
  hours = readregister(RDHR);
  minutes = readregister(RDMIN);
  seconds = readregister(RDSEC);

  sprintf(timestr,"time %d:%d:%d\n", hours, minutes, seconds );
  
  Serial.print(timestr);
}

int readregister(byte registernum)
{
  int value=-1;
  byte value_l=0, value_h=0;
  
  Wire.beginTransmission(RTCADDRESS);
  Wire.send(registernum);
  Wire.endTransmission();
  
  // Now do a transfer read
  Wire.requestFrom(RTCADDRESS, 1);

  if(Wire.available())
  {
     value_l = Wire.receive();
  }
  
  Wire.endTransmission();

  value = value_h << 8 | value_l;
  return value;
}

Okay, I quickly hooked up a mini and had the same problem. As soon as the Wire class is instantiated, everything goes to hell.

Just a guess, but someone trying to port the SPI code to a standard Arduino in which they had socketed an ATMega168 couldn’t get it to run and asked me to look at it. The problem was that some of the interrupt registers are different between the ATMega168 and the ATMega8. Specifically, GICR and probably some others, but that’s as far as I got before realizing there would need to be some source code modifications. Simple ones, but still…there was no way the code was going to compile.

Here’s my guess — Wire.o, which is what we’re trying to build against, was compiled for the ATMega8 and, hence, won’t work without being re-compiled for the ATMega168. Wire.cpp, wherever it may be, is needed to rebuild Wire.o for the ATMega168.

Just a guess. I’ll drop a note to Nicholas Zambetti, the guy who wrote Wire.

Julian

Thanks for confirming the problem, Julian.

I’m very interested to hear what you hear from Nicholas and especially figure out a way to get Wire fixed for the Mini. We’re rooting for him.

Okay, so — it was a simple matter to get TWI working on the Arduino Mini. I’ve documented the particulars here:

http://research.techkwondo.com/blog/julian/279

You’ll need to delete a couple of object files, and the posting explains where they are, etc. But…it works, no problems.

Julian

Excellent work. I’m looking forward to getting some time to try it soon.

Thanks for your followup. Much appreciated,

Landon

so can we now get the same functionality out of the arduino and arduino mini with this serial difficulty all cleared up?

I am looking at using some lcds sreens and would need to go the serial route becuase of all the ports it uses, and need to know weather i can use it with a mini.

Also is it easy to hook 2 arduinos up together?

thanks for any advise

ollie

While the two-wire interface is technically a serial interface, you probably mean RS-232 when you say you want to hook up LCD screens. If the LCD screens use a TWI protocol, I’d like to know where I can get some. If they use RS-232, then you could probably just use the standard USART functionality of the ATmega168 on the Arduino Mini and not think twice about TWI.

Hooking up two Arduinos…well, in principle, you should be able to do that using the SPI Serial Interface with one device the master and the other the slave. I’ve never done this before, so perhaps others can speak with more authority. But, certainly the ATmega168 and the 8, I’m pretty sure, have the architecture for a Master/Slave SPI Serial Interface. Check the long specification on the device — it’s all in there. avrfreaks.net probably has a dozen projects with examples of how to connect two Atmel microcontrollers together.

Julian