platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
138 stars 105 forks source link

Arduino I2C Wire no data #44

Closed ghost closed 7 years ago

ghost commented 7 years ago

Versions IDE: 17.3 Core: 3.2.1

Config

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_deps =
  Wire

I am trying to move from the Arduino IDE to platformio and that is not as simple as copy/paste but I am getting there. The issue I run into at the moment is an I2C device (LM75) using the Wire.h library that returns no data. I have taken out as many bits and pieces as possible to isolate the issue.

#include <Arduino.h>
#include <Wire.h>
#include <LM75.h>

LM75 sensor;

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

void loop() {
  // get temperature from sensor
  Serial.print("Current temp: ");
  Serial.print(sensor.temp());
  Serial.println(" C");

  // shutdown the sensor and wait a while
  sensor.shutdown(true);
  delay(3000);
  // wake up sensor for next time around
  sensor.shutdown(false);
  delay(1000);

  Serial.println();
}

This exact code works when I use the Arduino IDE but not when I use platformio. In the past this was due to difference in pin names. Here, since it is using I2C this will not be the case.

I have use an I2C Scanner and the code finds the chip and the address is as it should be, 0x48. But the request or read from wire gives an other result when I built with platformio than when I build with Arduinol IDE.

I have taken the Arduino Wire library and overwritten the platformio version (same code) with this just to be sure it's equal.

Added the library I use and a better example of my code LM75.zip

ivankravets commented 7 years ago

Does it work with the latest updates?

ghost commented 7 years ago

I can setup a test tonight, will update here.

ghost commented 7 years ago

The LM75 works great in platformio now :) awesome. Also tried it on the ATtiny85 again, still nothing, but thats another story.

Updated code, added line with Wire.begin()

#include <Arduino.h>
#include <Wire.h>
#include <LM75.h>

LM75 sensor;

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

void loop() {
  // get temperature from sensor
  Serial.print("Current temp: ");
  Serial.print(sensor.temp());
  Serial.println(" C");

  // shutdown the sensor and wait a while
  sensor.shutdown(true);
  delay(3000);
  // wake up sensor for next time around
  sensor.shutdown(false);
  delay(1000);

  Serial.println();
}