Go Down

Topic: Problem with I2C communication between ATTiny 85 and Raspberry pi (Read 307 times) previous topic - next topic

sodhani

I am using Arduino IDE to program ATTiny and Arduino as a programmer.
The proble is when I use delay(1000); in void loop() after sending a number let's say 10 to Raspberry pi via I2C I get value as zero. When I do I2C detect it detects all the the addresses. When I remove delay(1000); it works perfectly fine. Please address my problem.

AWOL

It's something to do with the code you didn't post.

HTH
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Unsigned_Arduino

I don't think you connected the grounds, Dave.
Did you connect the grounds together? Pulldown resistors? Pi Code? AVR code?

Sorry not much info to go by your post.  :smiley-confuse:


spycatcher2k

Don't use delay! Their are methods you can use to not use the delay command (HINT : in the examples supplied with the IDE, a sketch called 'blink without delay' will help)
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

DrAzzy

There is a bug or oversight in your code. Were you to post it, one of us might even be able to tell you where.
ATtiny core for 841+1634+828 and x313/x4/x5/x61/x7/x8 series Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts (some assembled), mosfets and awesome prototyping board in my store http://tindie.com/stores/DrAzzy

sodhani

I was using TinyWireS library, now I used Wire.h library of arduino it is working on attiny as well.
Thanks for your support.

sodhani

I am using this code to send two float type data via i2c from attiny85 to raspberry pi. I am not getting anything at raspberrypi side. Wire library works fine when I send just one byte of data.

Here is code for attiny85:
Code: [Select]

#include <Wire.h>

#define SLAVE_ADDRESS 0x04

#define FLOATS_SENT 2

float temperature = 10.5;
float luminosity = 5.2;
float data[FLOATS_SENT];

void setup() {
    pinMode(13, OUTPUT);
    Serial.begin(9600);
   
    data[0] = temperature;
    data[1] = luminosity;
   
    // initialize i2c as slave
    Wire.begin(SLAVE_ADDRESS);

    // define callbacks for i2c communication
    Wire.onRequest(sendData);
}

void loop() {
    delay(100);
}

void sendData(){
  Wire.write((byte*) &temperature, FLOATS_SENT*sizeof(float));
}


Raspberry pi code:

Code: [Select]

import struct
import smbus
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)

# This is the address we setup in the Arduino Program
address = 0x04

def get_data():
    return bus.read_i2c_block_data(address, 0);

def get_float(data, index):
    bytes = data[4*index:(index+1)*4]
    return struct.unpack('f', "".join(map(chr, bytes)))[0]

while True:
    try:
        data = get_data()
        print(get_float(data, 0))
        print(get_float(data, 1))
    except:
        continue
    time.sleep(1);


Moderator edit: [code] [/code] tags added.


sodhani

A update on that, this part// struct.unpack('f', "".join(map(chr, bytes)))[0]// do have errors in python3 but It do not give any error in python2.
Now I am able to read float values but after reading 15 values there is an error:input/output error.
Now, I am struck again.
please help me.

Go Up