felias-fogg / SoftI2CMaster

Software I2C Arduino library
GNU General Public License v3.0
368 stars 100 forks source link

Issue sending data #43

Closed hayden0b closed 3 years ago

hayden0b commented 5 years ago

I'm trying to read a voltage in from a power supply to an Arduino Micro, then send it to an oscilloscope through an I2C (MCP4725). I would use the default pins on the Micro but I want to wire three I2C and the default bus only allows two.

I've looked through examples and documentation but I can't seem to get it to send any data. I've been successful scanning (from examples) and finding the I2C addresses, so I assume that the trouble is at the end of my code.

Any tips would be greatly appreciated!

#define SDA_PORT PORTD
#define SDA_PIN 4 // = A4
#define SCL_PORT PORTC
#define SCL_PIN 6 // = A5
#include <SoftWire.h>

#define I2C_7BITADDR 0x62 //MCP4725

SoftWire Wire = SoftWire();

int aPin;

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

void loop(void){
  aPin = analogRead(A0); //read in from power supply
  Wire.beginTransmission(I2C_7BITADDR);
  Wire.write(aPin); //send voltage to osc.
  Wire.endTransmission();
}
felias-fogg commented 5 years ago

Hi,

where does it say that you can only attach two I2C devices to the bus? You can attach as many slaves to the bus as you can address. If there are many slaves and perhaps the wires get longer, you may want to use pull-ups, which are a bit lower. Note that when adding no pull-ups on the standard pins, only the internal pull-ups are used (roughly 50kΩ).

Note that you should also wire pull-ups to the bus (around 4.7 kΩ) if you are using the SoftWire code. I just checked the pinout of the Arduino Micro and PD4 corresponds to Arduino pin D4 and A8 (not A4!) and PC6 is D5. I guess, you just forgot to change the comment.

Concerning your code: analogRead returns 2 bytes (with numbers up to 1023) while the write method expects 1 byte. In this case, only the LSB will be transmitted. Otherwise it seems OK.

Best, Bernhard

Am 11.07.2019 um 12:49 schrieb bread-0 notifications@github.com:

I'm trying to read a voltage in from a power supply to an Arduino Micro, then send it to an oscilloscope through an I2C (MCP4725). I would use the default pins on the Micro but I want to wire three I2C and the default bus only allows two.

I've looked through examples and documentation but I can't seem to get it to send any data. I've been successful scanning (from examples) and finding the I2C addresses, so I assume that the trouble is at the end of my code.

Any tips would be greatly appreciated!

define SDA_PORT PORTD

define SDA_PIN 4 // = A4

define SCL_PORT PORTC

define SCL_PIN 6 // = A5

include

define I2C_7BITADDR 0x63 //MCP4725

SoftWire Wire = SoftWire();

int aPin;

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

void loop(void){ aPin = analogRead(A0); //read in from power supply Wire.beginTransmission(I2C_7BITADDR); Wire.write(aPin); //send voltage to osc. Wire.endTransmission(); }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.