Adafruit to AVR

Go To Last Post
33 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

Im working on a small atmega project and what I want is to measure the temperature and connect it to some status leds.

Because I'm new to AVR I tried to make a simple code for the arduino micro pro that has has the same microcontroller that im going to work with(atmega32u4)

The temperature sensor I'm working with is the Adafruit MCP9808.

So my problem is that I use the libraries like Wire.h and Adafruit_MCP9808.h which wont work on the atmega32u4 (because of the c++ stuff in the libraries(not too sure about this though))

 

If i want to use my arduino code for Atmega32u4, what do i need to do:

rewrite the libraries to c?

look for a similair library?

make my own library with I2C and stuff(seems a bit difficult but I'm open for it)?

 

#include <Wire.h>
#include "Adafruit_MCP9808.h"
#include <stdio.h>
#include <stdbool.h>

// prototype functions
float readTempC();
void statusLED(float c);

// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808(); // need to change this for AVR gcc

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("start");

  //PINMODE LED'S
  DDRD |= (1 << DDD4); //digital pin 4 is output // red
  DDRC |= (1 << DDC6); //digital pin 5 is output // blue
  DDRD |= (1 << DDD7); //digital pin 6 is output // green

  // Make sure the sensor is found, you can also pass in a different i2c
  // address with tempsensor.begin(0x19) for example
  // need to change this for ACR gcc
  if (!tempsensor.begin()) {
    Serial.println("Couldn't find MCP9808!");
    while (1);
  }
}

void loop() {

  float c;

  while (true)
  {
    c = readTempC();        // read temperature
    statusLED(c);           // set new LED status
    Serial.println(c);
    delay(1000);
  }
}

float readTempC() {
  return tempsensor.readTempC();    // need to change this for AVR gcc
}

void statusLED(float c) {
  char function;
  if (c <= 10.0) {
    function = 1;
  }
  else if (c >= 30.0) {
    function = 2;
  }
  else {
    function = 3;
  }

  switch (function)
  {
    case 1: // too cold
      PORTD &= ~(1 << PORTD4); //digital write 4 low  // red
      PORTC |=  (1 << PORTC6); //digital write 5 high // blue
      PORTD &= ~(1 << PORTD7); //digital write 6 low  // green
      break;
    case 2: // too hot
      PORTD |=  (1 << PORTD4); //digital write 4 high // red
      PORTC &= ~(1 << PORTC6); //digital write 5 low  // blue
      PORTD &= ~(1 << PORTD4); //digital write 6 low  // green
      break;
    case 3: // nice
      PORTD &= ~(1 << PORTD4); //digital write 4 low  // red
      PORTC &= ~(1 << PORTC6); //digital write 5 low  // blue
      PORTD |=  (1 << PORTD7); //digital write 6 high // green
      break;

  }
}

Tips or links to relevant forums would be very handy!

thanks in advance

This topic has a solution.
Last Edited: Wed. Jul 18, 2018 - 07:17 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Surely the Leonardo means there is a "core" that supports Arduino on 32U4?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let me see if I understand: you wrote the code for an Arduino pro micro, which has atmega32u4 and it works. Your actual product also has a mega32u4. So what is the problem? Why can't you use the Arduino code? They don't run at the same clock or something?

 

edit: Ah, ok the problem you have is wire.h and wire.cpp

But surely it must work with mega32u4, since pro micro and leonardo use this chip?

Last Edited: Mon. Jul 9, 2018 - 02:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was thinking the same thing.

Im not able to test it yet, because im gonna need a programmer first.

But I wasnt able to find the awnser so I made this post.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://learn.adafruit.com/adafruit-mcp9808-precision-i2c-temperature-sensor-guide/arduino-code

 

Adafruit indicates this will work with the Leonardo/Micro, per the above link:

 

  • Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3
  • Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2

Start out with the test in their Github, once you get that, then tweak to taste.

 

I would advise learning how to debug via serial output and the Arduino Serial Monitor to see why your code isn't behaving how you think it should, the problem isn't in the libraries.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I've seen this, but listen up.

The code is working just fine. But its working on the micro pro with the Arduino IDE.

But im going to switch to just the Atmega 32u4 chip and avr gcc atmelstudio.

I wanted to know if its still possible with the same code and same libraries, because I've read on some forums that there are problems with arduino being c++.

And if its not possible, whats the best way to solve this problem.

 

And like I've mentioned before im not able to test yet if it will work on atmel studion.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

IIRC ,

a) recent versions of A Studio can import arduino sketches and libraries.

b) avr-g++ has benn existing for ages, and is supported by A studio

 

Perhaps you should begin ... with arduino software and hardware (advantages : HW is pressoldered; if you import adafruit library, it will come with an example (oh, you already simplified the example, removing Fahrenheit display). other adavntage : new peripherals are likely to come with an arduino demo software; buying an extra arduino can quickly answer the question : does hardware work?

 

Edited I had a quick and superficial look at https://github.com/adafruit/Adaf... (less than 150 lines) :

there are 4 basic functions, write16, read16, requestfrom which handle the TWI interface (and are TWI peripheral agnostic)

then,  begin, readTempC (maybe shutdown_wake) are very easy to port to c -if needed : see -b) -

Last Edited: Mon. Jul 9, 2018 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Did you try to run the demo from Adafruit for the sensor on your pro-micro?   What were the results?

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not sure why you would need the results. The program isnt that complicated, the hardware works good, everything works.

I just want to know if I can replace my micro for just the atmega32u4 withouth having to change the libs.

 

there are 4 basic functions, write16, read16, requestfrom which handle the TWI interface (and are TWI peripheral agnostic)

then,  begin, readTempC (maybe shutdown_wake) are very easy to port to c -if needed : see -b) -

 
 

This was my first option of my thread and if you say its basic stuff, then I think its do-able for me :D .

Thank you all!

Last Edited: Mon. Jul 9, 2018 - 02:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The compiler in AS7 is the same one as in Arduino IDE, the only thing you gain in AS is using a debugger.  You can import your Arduino sketch into AS as is and it should work.

What is the need for moving to AS7 if the code works in Arduino?

 

Jim

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"if you say its basic stuff, then I think its do-able for me"

 

Well, "being doable" does not mean "it must be done"

 

If you want to use A Studio, you might answer some questions:

is it easy -subjective notion-  to import Arduino examples into A Studio(in the short term - my answer would be "no"; in the middle/long term ? my answer would be "yes") This can be answered by building, without programming a chip.

are there better avr- TWI libraries than Arduino's (for me, I am satisfied with Arduino; but you can have your own criteria). This one can be answered -maybe- by reading and knowing what one wants.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As others have said the transition from AS6 to AS7 saw the addition of an "arduino importer" to AS7. So you just "create project from INO" and it will pull in all the wire.h and wire.cpp and whatever else is needed to build the code as an AS7 project. All that then remains is to get the .hex that is built back into the "stand alone" 32U4. If you have wired this up just like a 32U4 in an Arduino Leonardo with the same connections, same crystal speed and so on then all you need do is use ISP (and an Arduino can be used for that) to "burn bootloader" into the stand alone 32U4 then, for all intents and purposes is IS now an arduino so in As7 you just follow one of the myriad internet tutorials that tells you how to add a programming button/toolbar icon/whatever to As7 that, when invokved, runs a copy of avrdude and it will have the "usual" bootloader conversation with the bootloader now in the stand alone 32U4 and it will accept the hex and program it in.

 

BTW unless you are planning to use a debugger what do you think is to be gained by building in AS7 versus building in Arudino? They both invoke a very similar avr-g++ to do the actual code compilation. After that it's really just about editor features and for that you can just use your own favourite editor (Notedpad++ ?) alongside the Arduino IDE anyway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The reason I'm using AS7 (Its called AtmelStudio, but I downloaded it recently so Im pretty sure its AS7)

is because Im working in a project, and we are all using Atmelstudio.

Last Edited: Mon. Jul 9, 2018 - 03:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Fair enough then the importer should do it for you.

 

If you DID want to ditch "Wire" then the "common C" solution most folks use for TWI/I2C with the avr-gcc compiler is the Fleury code at:

 

code: http://homepage.hispeed.ch/peter...

manual: http://homepage.hispeed.ch/peter...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

From Clawsons link :

Fleury  code can cope with errors and even cope with hardware TWI ... (Arduino does not always check for errors : ex.  Wire.beginTransmission does not return an error code,  Fleury i2c_start does ).

 

Serial -if not used "only" for debugging -  can be more complicated (but OP colleagues can show) : it does not display floats (arduino's "debugging " console showed floats)  by default  see https://www.nongnu.org/avr-libc/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JPdeRie wrote:
Yes I've seen this, but listen up.
 

 

I'm listening. 

 

clawson wrote:

As others have said the transition from AS6 to AS7 saw the addition of an "arduino importer" to AS7. So you just "create project from INO" and it will pull in all the wire.h and wire.cpp and whatever else is needed to build the code as an AS7 project. All that then remains is to get the .hex that is built back into the "stand alone" 32U4.

 

That used to be the case, but they built all the main Arduino libraries into AS7 a while back, that import function isn't needed anymore, nor is Visual Micro's third party plug in. 

 

Now when you start a project within AS7, you have the ability to select "Arduino Project" and then your Arduino board, and it'll pull the needed GCC libraries in. 

 

The original poster has been misinformed, Atmel Studio is fully GCC compatible, which is what Arduino is based on. Their concern about 32u4 isn't an issue, there are plenty of Arduino boards with that part to choose from the 'boards selection'. All the original poster needs to do is make sure they're using a part with the same frequency external crystal/oscillator as the Arduino board and they'll be good to go. 

 

The only thing left is learning how to include the Adafruit library to AS7, which isn't too hard. 

Last Edited: Tue. Jul 10, 2018 - 12:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

they built all the main Arduino libraries into AS7 a while back, that import function isn't needed anymore, nor is Visual Micro's third party plug in. 

Now when you start a project within AS7, you have the ability to select "Arduino Project" and then your Arduino board, and it'll pull the needed GCC libraries in. 

I don't see that anywhere.  I just downloaded 7.0.1931 (latest online installed.)

Alas, Studio seems to have several update/feature managers that I've never bothered to learn how to use, so I'm not sure if I know where to look for something that would enable it. :-(

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If i want to use my arduino code for Atmega32u4, what do i need to do:

rewrite the libraries to c?

look for a similair library?

make my own library with I2C and stuff(seems a bit difficult but I'm open for it)?

 Yep; one of those.  :-)

 

The Arduino code layers the temp sensor support on top of another Arduino library ("Wire") that is a general purpose I2C library in C++.

So you have options:

I2C library:  (write from scratch) (find C library) (rewrite Arduino library)

MCP9808 lib: (write from scratch) (find C library) (rewrite Arduino library)

                  (write or find MCP9808 code that uses I2C, without implementing an I2C library)

 

If you are a student, there may be academic standards and codes of conduct that apply to "finding" code.

If you are a professional working on a commercial project, there may be licensing issues that you should pay attention to.

If you are a tiny cog at a big company, you may want to see if there is already a "preferred" I2C library for AVR.

For most other cases I can think of, you should probably be asking "why can't we just use Arduino C++ code, imported into Studio, or not?"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, out of the 4 options, I exclude professional use (would likely be a blunder against OP's hierarchy).

 

For academic standard, finding a better library than Arduino's wire and explaining why could be a benefit -and teachers , if they are competent -this is an optimistic bet- can appreciate someone making efforts to understand another library.

For hobbyist uses (this is how I see "most other cases"), deciding there is a (slightly) better library can be interesting if weather is not too hot.

 

Clawson hinted at Fleury I2C/TWI , which is slightly better than Arduino wire :

 

a) eats less RAM/flesh

 

b) checks for error returns -ion the long term, can be very useful-

 

c) can use software I2C (this part has already been ported to Arduino playground  https://playground.arduino.cc/Ma...) if one has already used HW I2C pins...

One of the pitfalls would be that Arduino TWI adresses must be multiplied by 2 (and sense bit must be added; shift side depends on the chip orientation) to convert them into Fleury adresses.

 

I do not know whether arduino can cope with assembly (can cope with plain C, and of course c++)

 

I bet that adafruit MCP library becomes very simple to adapt to this change (< 150 lines 10/20 % being conditional macros and ... empty lines).

 

OTOH, Serial library (used for debugging) -but is it needed if AStudio debuuger  works and is easy ?-  is difficult to make better (has a 32 byte ring buffer, can cope with many data types to print)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:

I do not know whether arduino can cope with assembly (can cope with plain C, and of course c++)

 

It can do the same as any other IDE. The Arduino IDE processes ".cpp", ".c", ".S", etc. like any other avr-gcc based IDE such as Atmel Studio. The only files that are processed differently are ".ino", they are like ".cpp" but receive special Arduino preprocessing.

So, if you simply provide an empty "*.ino" file, that is, no setup(), no loop(), nothing, (the IDE requires one with the same name as the project directory), then all Arduino stuff is disabled and the Arduino IDE will behave like, basically, an Atmel Studio C++ project.

Last Edited: Tue. Jul 10, 2018 - 01:16 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, that remains removes half the difficulties I saw for using Fleury I2C and TWI library (I knew Arduino could cope with plain C, and did not dare to dream it would cope with .S : http://forum.arduino.cc/index.ph... confirmed it).

" the Arduino IDE will behave like, basically, an Atmel Studio C++ project."

 

But  (their IDE is slowly improving/improved slowly)

 

a) a simulator will be missing (maybe it is seldom used: might be interesting on the long therm)

 

b) a debugger will be missing (I do not know whether A Studio debugger is ... debugged -if needed- and easy)

Last Edited: Tue. Jul 10, 2018 - 03:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dshay wrote:
they built all the main Arduino libraries into AS7 a while back, that import function isn't needed anymore

Are you sure?

 

Last time I looked (which is, admittedly, a while ago), it was still necessary to do the import.

 

nor is Visual Micro's third party plug in. 

That is true:  the import functionality is now built-in - no plug-ins required.

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dbrion0606 wrote:

" the Arduino IDE will behave like, basically, an Atmel Studio C++ project."

 

But  (their IDE is slowly improving/improved slowly)

 

a) a simulator will be missing (maybe it is seldom used: might be interesting on the long therm)

 

b) a debugger will be missing (I do not know whether A Studio debugger is ... debugged -if needed- and easy)

 

Well, of course it won't have the same features, for example code navigation is much worse, etc., it's a very limited IDE. But I'm pretty sure it will be able to compile most code you can write in a AS C++ project (for MCUs used in Arduino), no matter if it's mixed with straight C or asm. You just need to add the empty ".ino" file.

 

I like to use the Arduino IDE for small tests and code snippets.

Last Edited: Tue. Jul 10, 2018 - 03:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seems A Studio has too many buttons ( do people know how many? from this very thread, seems complicated) and Arduino has too few(but their number and functionalities slowly but nicely  increases : I saw improvements in Arduino 1.8.x for arm-linux over A 1.0.x )

Maybe xxPi users should wait a time, until buttons are removed and it is arm-linux ported....

And I guess OP may remain with Arduino or use A Studio  (or both)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

dshay wrote:
they built all the main Arduino libraries into AS7 a while back, that import function isn't needed anymore

Are you sure?

 

Last time I looked (which is, admittedly, a while ago), it was still necessary to do the import.

 

nor is Visual Micro's third party plug in. 

That is true:  the import functionality is now built-in - no plug-ins required.

 

 

 

westfw wrote:

they built all the main Arduino libraries into AS7 a while back, that import function isn't needed anymore, nor is Visual Micro's third party plug in. 

Now when you start a project within AS7, you have the ability to select "Arduino Project" and then your Arduino board, and it'll pull the needed GCC libraries in. 

I don't see that anywhere.  I just downloaded 7.0.1931 (latest online installed.)

Alas, Studio seems to have several update/feature managers that I've never bothered to learn how to use, so I'm not sure if I know where to look for something that would enable it. :-(

 

Ok, so I just pulled up Atmel Studio again to see what's under the hood, as it's been a little while since I used this feature. 

 

One prerequisite is one must have the Arduino IDE preinstalled for this to work. 

 

 

Click New > Project

 

Then Select > Create project from Arduino Sketch. 

 

You then need to browse to select the location of your Sketch file. This can be an empty Setup Loop template, this can be an example sketch in the included files, or a prewritten Sketch from Arduino. 

 

You need to browse the Arduino IDE execute path ( you only have to do this once, it gets prefilled after )

 

Then Select the board, in my case I'm looking at an Adafruit Itsy Bitsy 32u4 3V 8mHz, that I followed Adafruit's instructions on how to import into Arduino IDE. 

 

Then Select Device, in my case atmega32u4. 

 

You don't have to import the libraries any more, when you provide Atmel Studio with the IDE path Atmel Studio knows exactly where to go fetch them because Arduino's IDE has a set file structure. 

 

 

 

 

 

 

 

Last Edited: Tue. Jul 10, 2018 - 06:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Arduino has a feature where the program application code (the .ino file) can be compiled directly into a pair of .hex files that can be loaded into the AVR IC using ISP.  With this feature you can develop using Arduino libraries and functions (like analogRead(), etc... ), and then load the compiled code directly into a different IC of the same AVR device type and have it run as if it were on the Arduino development board.  In the Arduino IDE, go to Sketch on the menu bar, then select Export Compiled Binary at the bottom of the list.  This creates two hex files with the sketch name at the beginning of the file name.  One of the hex files is just the application compiled code and the other includes the bootloader code with the application.  These files are found in the same directory as the .ino file.  The bootloader-include file has "boot" in its name.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dshay wrote:
You don't have to import the libraries any more, when you provide Atmel Studio with the IDE path Atmel Studio knows exactly where to go fetch them because Arduino's IDE has a set file structure. 

OK - I see what you're saying.

 

AIUI, Atmel Studio 7 does still import the libraries,  but it does it "behind the scenes"  - it's not something that the user has to do manually.

 

Atmel Studio 7 effectively takes a "snapshot"  of the sketch & required libraries.

 

But I could be wrong (or just out-of-date).

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

Arduino has a feature where the program application code (the .ino file) can be compiled directly into a pair of .hex files that can be loaded into the AVR IC using ISP.  With this feature you can develop using Arduino libraries and functions (like analogRead(), etc... ), and then load the compiled code directly into a different IC of the same AVR device type and have it run as if it were on the Arduino development board.  In the Arduino IDE, go to Sketch on the menu bar, then select Export Compiled Binary at the bottom of the list.  This creates two hex files with the sketch name at the beginning of the file name.  One of the hex files is just the application compiled code and the other includes the bootloader code with the application.  These files are found in the same directory as the .ino file.  The bootloader-include file has "boot" in its name.

 

After that if you want to continue developing on micro using the bootloader within Atmel Studio 7

 

>Tools 

 

      > External Tools 

 

                    Title <Program *name of microcontroller here* with Bootloader>

 

                    Command >           C:\AVRDude\avrdude.exe    //or use the file location of AVRDude within Arduino IDE if you want to avoid installing AVRDude again

 

                    Arguments >         -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -p atmega328p -c arduino -P COM4 -b 115200 -U flash:w:$(ProjectDir)$(TargetName).hex:i

 

                    Initial Directory>     C:\AVRDude\               //location of AVRDude.conf file  

 

the AVRDude command -D isn't needed in the above example because you'd be using the bootloader to program the device, it's not going to overwrite itself. If you're using a USBISP programmer and a full bootloader and project file you'd include -D in the above, after doing a similar AVRDude command to program fuse bits. 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"You don't have to import the libraries any more, when you provide Atmel Studio with the IDE path Atmel Studio knows exactly where to go fetch them because Arduino's IDE has a set file structure. "

 

Does it copy as it is at the time you import?

or

does it manage to copy(/symbolic link : updates would be automagic)   again, if Arduino file structure or -incl- content changes (it happens sometimes: with Adafruit, wire and Serial, I admit it is very unlikely... but not fully impossible)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

AIUI, it is a straight copy - a "snapshot".

 

So that the imported project becomes completely independent of the Arduino IDE - so any changes or updates in Arduino-land will not be seen.

 

That's my understanding, anyhow - it could be wrong...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, that is why I hoped ... for an independant confirmation (this is not directly linked with OP issue, but both ways, say

a) copy and fork

b) sym. link

have drawbacks and advantages (if arduino slowly improves, why should A Studio ignore it (b is better) ; OTOH, if a given UE is misleading (too many/too few buttons) and leads to horrors, (a) is better. On the middle term, this info might avoid unpleasant things)

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#UPDATE

 

so I changed the adafruitlibrary to C and used I2C_master instead of wire.h.

There were some changes I had to make in I2C_masters, like shifting the address to the left and adding a R/W bit(I dont know why this wasnt implemented)

Thought the program wasnt working correct because when I was debugging I put breakpoints in the I2C_master start function which cause for unsynchronisation(twst kept returning 32)

Its all working now!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

" like shifting the address to the left and adding a R/W bit(I dont know why this wasnt implemented)"

 

Well, there are two solutions for I2C  adresses :

Arduino one and "Astudio"  .

 

As nobody knows which one is the best, one must know adresses , when using arduino,  should sometimes (depends on the seller) be divided by 2 (arduino copes wit the read write issues).