Attiny - Tinywire send strings

Hello,

I have been trying to get a Attiny85 (running as master) to talk to a arduino UNO (running as slave) over the I2C bus. I have the TinyWire library running on the Attiny. I can get the Attiny to send a single byte to the arduino by running this code:

#include <TinyWireM.h>                  

void setup() {
  TinyWireM.begin();
}

byte x = 0;

void loop() {
  TinyWireM.beginTransmission(4);
  TinyWireM.send(x);
  TinyWireM.endTransmission();
  
  x++;
  delay(1000);
}

But when I run this code to send a string to the Arduino:

#include <TinyWireM.h>                  

void setup() {
  TinyWireM.begin();
}

void loop() {
  TinyWireM.beginTransmission(4);
  TinyWireM.send("Hello world");
  TinyWireM.endTransmission();
  
  delay(1000);
}

I get this error:

Tiny85_Temp.pde: In function ‘void loop()’:
Tiny85_Temp:9: error: invalid conversion from ‘const char*’ to ‘uint8_t’
Tiny85_Temp:9: error: initializing argument 1 of ‘void USI_TWI::send(uint8_t)’

Any help would be appreciated

Thanks in advance
Nathan

I think you will need to write a loop to send each character in your string one at a time.

TinyWireM.beginTransmission(4);
char myString[12] = "Hello world";
for(byte i = 0; i <= strlen(myString); i++)
  { TinyWireM.send(myString[i]); }
TinyWireM.endTransmission();

The "uint8_t" in your error message is a byte (unsigned 3-bit). Take a look at the source code for the send function call in TinyWireM library.

Best to declare the variables you need to send using a Union, and then just send them (text, long, float, short, etc.) as bytes, one byte at a time.

http://www.pvtuts.com/cpp/cpp-struct-union

Hope that helps.

borland:
Best to declare the variables you need to send using a Union, and then just send them (text, long, float, short, etc.) as bytes, one byte at a time.

More than one way to skin a cat. You could use pointers instead of a union:

void setup()
{
Serial.begin(38400);
}

void loop()
{
  {
  char myVar = 'A';
  Serial.print("char ");
  char* ptr = (char*)&myVar; // get a pointer to any data type: char, byte, int, long, float, string
  for(byte i=0; i < sizeof(myVar); i++) // for each byte in myVar,
    {
    Serial.print((byte)*ptr); Serial.print(" "); // output one byte
    ptr++; // point to the next byte
    }
  Serial.println(""); 
  }
  {
  byte myVar = 128;
  Serial.print("byte ");
  char* ptr = (char*)&myVar; // get a pointer to any data type: char, byte, int, long, float, string
  for(byte i=0; i < sizeof(myVar); i++) // for each byte in myVar,
    {
    Serial.print((byte)*ptr); Serial.print(" "); // output one byte
    ptr++; // point to the next byte
    }
  Serial.println(""); 
  }
  {
  int myVar = 258;
  Serial.print("int ");
  char* ptr = (char*)&myVar; // get a pointer to any data type: char, byte, int, long, float, string
  for(byte i=0; i < sizeof(myVar); i++) // for each byte in myVar,
    {
    Serial.print((byte)*ptr); Serial.print(" "); // output one byte
    ptr++; // point to the next byte
    }
  Serial.println(""); 
  }
  {
  long myVar = 65538;
  Serial.print("long ");
  char* ptr = (char*)&myVar; // get a pointer to any data type: char, byte, int, long, float, string
  for(byte i=0; i < sizeof(myVar); i++) // for each byte in myVar,
    {
    Serial.print((byte)*ptr); Serial.print(" "); // output one byte
    ptr++; // point to the next byte
    }
  Serial.println(""); 
  }
  {
  float myVar = 1.1;
  Serial.print("float ");
  char* ptr = (char*)&myVar; // get a pointer to any data type: char, byte, int, long, float, string
  for(byte i=0; i < sizeof(myVar); i++) // for each byte in myVar,
    {
    Serial.print((byte)*ptr); Serial.print(" "); // output one byte
    ptr++; // point to the next byte
    }
  Serial.println(""); 
  }
  {
  char myVar[16] = "Hello, world";
  Serial.print("string ");
  char* ptr = (char*)&myVar; // get a pointer to any data type: char, byte, int, long, float, string
  for(byte i=0; i < sizeof(myVar); i++) // for each byte in myVar,
    {
    Serial.print((byte)*ptr); Serial.print(" "); // output one byte
    ptr++; // point to the next byte
    }
  Serial.println(""); 
  }
Serial.println(""); 
delay(1000);
}