Bananian

[solved] how to use i2c on bananian?

2 1334
aDAMrus  
Edited by aDAMrus at Feb 01, 2016 15:28

Hello!
Need info about usage i2c on bananian (OMV debian7 image).

Trying to connect lm35 termal sensor via arduino (as ADC to i2c. Surprised what babana pi has no ADC) to Banana Pi. Tested connection between two arduinos - ok, but nothing with banana pi... Searching on google with no result...

Thanks!
aDAMrus  
Edited by aDAMrus at Jan 17, 2016 07:14

So, I connected it. Banana find arduino. Next problem is a code.
I trying to use WiringPi...

  1. #include <wiringPi.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdint.h>
  5. #include <wiringPiI2C.h>

  6. int main (void)
  7. {
  8.   int fd;
  9.   int tempC;
  10.   fd = wiringPiI2CSetup (0x08); //08 is a arduino adress
  11.      for (;;)
  12.         {
  13.                 tempC = wiringPiI2CRead(fd);
  14.                 printf ("temp= %d\n", tempC);
  15.             delay(1000);
  16.         }
  17. return 0;
  18. }
Copy the Code
...result give me only 0... and -1 if break i2c wire...

aDAMrus  
Edited by aDAMrus at Jan 21, 2016 10:37

Resolved!
Problem was in code on Arduino side.
So, simple example to use analog temp sensor lm35 (with Arduino as ADC) is:

Arduino side:
  1. #include <Wire.h>

  2. int reading; //analog read from lm35
  3. int tempPin = 6;  //pin to lm35
  4. int tempC = 0; //default temp

  5. void setup()
  6.    {
  7.     Wire.begin(8); //set the Arduino i2c adress
  8.     pinMode(6, INPUT);
  9.     Wire.onRequest(requestEvent);
  10.     analogReference(INTERNAL);
  11.    }

  12. void loop()
  13.    {
  14.     delay (1000);
  15.    }
  16. void requestEvent()
  17. {
  18.   reading = analogRead(tempPin); //analog IN to Arduino
  19.   tempC = reading / 12; //correction temp
  20.   Wire.write(tempC);//digital OUT to Banana
  21.   delay(3000);
  22. }
Copy the Code


Banana side:
  1. #include <wiringPi.h>
  2. #include <stdio.h>
  3. #include <wiringPiI2C.h>

  4. int main (void)
  5. {
  6.   int fd;
  7.   int tempC;
  8.   fd = wiringPiI2CSetup (0x08); //08 is a arduino adress
  9.      for (;;)
  10.         {
  11.                 tempC = wiringPiI2CRead(fd);
  12.                 printf ("temp= %d\n", tempC);
  13.             delay(1000);
  14.         }
  15. return 0;
  16. }
Copy the Code

You have to log in before you can reply Login | Sign Up

Points Rules