Plug & play components connected to Spark Core

Hi everyone,

I’m working on a project which will involve plug & play components. For example, the Core needs to be able to detect if a connected component is a servo or a motor.

In this example I presume the motor and servo would need to be part of their own circuits, with an extra component to identify them. Does anyone have examples of this being done elsewhere with the Core or Arduino?

Any advice would be great.

Thanks!

You could have a “sense” or “id” pin with a certain resistor value on that. A 1k resistor is a motor, a 2k is a server, etc. This method eats up analog input however

You could look into http://www.atmel.com/products/memories/serial/i2c.aspx

Or, and this is obviously more expensive, you could make each plug and play item “smart”. So, a servo would be a servo + a small micro (ATINY?) which you communicate with over I2C. To determine what’s up you just need to query the I2C bus (see http://playground.arduino.cc/Main/I2cScanner for example). That would be cool and would only ever tie up the I2C lines, power, and gnd

1 Like

The second approach sounds most sensible. The number of possible components is likely to expand beyond just motors and servos, so I don’t want to be limited by the number of resistor types. I’ll have a look at I2C. Would it be possible to make this work with multiple items connected at one time though?

Another challenge is how I power each item correctly, given they’ll have different requirements.

@tw_uk, there also one-wire eeprom that would use a single pin.

As for power, you will need device power and logic power. You may want to look at Arduino shields and breakouts as they usually separate the two.

1 Like

You could have a spec for 5 wires: GND, 3.3V, 5V, I2C, I2C. That should satisfy most power requirements.

A cool idea. Let me know if you want some help with it. I’d be happy to provide some firmware help once you decide on a slave IC. I’ve got a couple of ATTINY45s here if you decide to go that route I could help

Thanks. 1-wire looks like it’s a good option, e.g.

http://www.maximintegrated.com/en/products/digital/memory-products/DS2431.html

Would I need one pin for the EEPROM, and one for the motor transistor…or is there a way of integrating the two?

Yea you would. That’s why I like the ATTINY/I2C option, only 1 set of pins every time no matter the component.

@harrisonhjones, when @timb was here we discussed using an MPS430 processor on ALL shields he was designing. It was to use I2C to communicate with the Core and create “smart” shields (like the ATINY you propose). He was planning one on his power shield. Though smart shields cost a little more, they defer processing away from the Core. One idea was an SD and/or FRAM shield that did all the FAT processing for example. :smile:

2 Likes

That sounds awesome. I honestly wish that’s how all shields (Arduino included) worked. It would be harder for new comers wanting to learn electronics perhaps but it would make prototyping so easy

1 Like

I got some ATtiny85s, and a Sparkfun Tiny AVR Programmer, but can’t seem to get the communication working. I’m using the Spark as the master, to request data from the slave ATtiny85. That could then return an ID that identified this component.

Below is the code. The Spark uses the Wire library, and the ATtiny85 uses TinyWireS.

Do you think this is good approach, and can you see what might be wrong? If I try logging from the ATtiny85 it works fine, so I think the circuit is correct.

Spark code

#include <Wire.h>

#define SLAVE_ADDR 0x50

void setup()
{
    Wire.begin();
    Serial.begin(9600);
}

void loop()
{
  Wire.requestFrom(SLAVE_ADDR, 1);

  while(Wire.available())
  { 
    byte byteReceived = Wire.read();
    Serial.println(byteReceived, DEC);
  }
}

ATtiny85 Code

#include "TinyWireS.h"

#define SLAVE_ADDR 0x50

void setup()
{
  TinyWireS.begin(SLAVE_ADDR);
  TinyWireS.onRequest(requestEvent);
}


void loop()
{
}

void requestEvent()
{
  byte byteToSend = 23;
  TinyWireS.send(byteToSend);
}

@tw_uk, are you using 4.7k pull-up resistors on both I2C lines? The should be connected to 3.3V ideally.

At the moment I still have the ATTiny powered from the USB programmer, with the I2C lines connected to pins 3/4 through the prototyping pins.

@tw_uk, I2C will not work without pull-up resistors.

2 Likes

@peekay123 Hmm stick no luck here. I have 4.7k resistors on both lines, connected to 3.3V. Serial communication still works fine.

@tw_uk, now that I think of it, you should pull-up to 5v or the ATtiny may not like it :smile:

@peekay123 Yeah, I tried this with my Arduino Uno too with the 5V pin. Still the same result. Strange…

@tw_uk, which TinyWireS library are you using? The standard Arduino TinyWireS library does not have “onRequest”.

I tested your code with an Arduino Pro Mini and the Wire library and it worked fine. I need to know which ATtiny library you are using so I can test with an ATtiny85 :smile:

I’m using this one: https://github.com/rambo/TinyWire/tree/master/TinyWireS

@tw_uk, got it working!

Here is the pin-out with 4.7K ohm resistors to 5V on SDA and SCL. The Spark is powered via USB and I am using the Vin output to power the ATtiny.

    ATtiny85       Spark
    ----------------------------
    8 (Vcc)        Vin
    7 (SCL)        D1
    5 (SDA)        D0
    4 (GND)        GND

I programmed the ATtiny85 using a TinyLoadr board on an Uno using “Arduino as ISP” programming mode. :smile:

1 Like

Hey @peekay123 thanks for answering @tw_uk’s question. I was out of town this weekend. I’m looking forward to trying my hand at the same code. Ghetto open servo maybe?

1 Like