Pages: [1]   Go Down
Author Topic: Compass Sensor Library with ATtiny  (Read 2590 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

I have a compass sensor (HMC5883L on a GY-271 board, I couldnt find a datasheet). I successfully got it to run following a tutorial with a library for a similar board with the same sensor on an Arduino Uno.

For my actual project I want to get rid of the big Arduino board and control it with an ATtiny 85.
I am facing two problems:
The two analog pins that communicate with the sensor are hardcoded into the library and the ATtiny doesnt have Analog Input 4 and 5.
The other problem is that the Library uses Wire.h which doesnt compile with the ATtiny selected as board:
Code:
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c: In function 'twi_init':
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:76: error: 'SDA' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:76: error: (Each undeclared identifier is reported only once
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:76: error: for each function it appears in.)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:77: error: 'SCL' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:80: error: 'TWSR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:80: error: 'TWPS0' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:81: error: 'TWPS1' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:82: error: 'TWBR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:90: error: 'TWCR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:90: error: 'TWEN' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:90: error: 'TWIE' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:90: error: 'TWEA' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c: In function 'twi_setAddress':
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:102: error: 'TWAR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c: In function 'twi_readFrom':
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:154: error: 'TWDR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:155: error: 'TWCR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:155: error: 'TWINT' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:155: error: 'TWEA' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:155: error: 'TWEN' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:155: error: 'TWIE' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:159: error: 'TWSTA' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c: In function 'twi_writeTo':
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:234: error: 'TWDR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:235: error: 'TWCR' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:235: error: 'TWINT' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:235: error: 'TWEA' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:235: error: 'TWEN' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:235: error: 'TWIE' undeclared (first use in this function)
C:\Program Files\Arduino\arduino-1.0.1\libraries\Wire\utility\twi.c:239: error: 'TWSTA' undeclared (first use in this function)
[...]

I was unable to find the part of the library that defines the two pins.
Also, Im not sure if its easier to code the sensor communication myself or to modify the libraries since I dont know how exactly the sensor data is transmitted.

What is the easiest way to get the angle value of the compass on an ATtiny?
« Last Edit: October 18, 2012, 09:00:52 am by marian42 » Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

the ATtiny13 cant do that itself...
u had to do it with ur own routins...

the ATtiny[248]5 can possibly do it with its USI things... but i'm not sure...

in each case the lib needs some work if u want to port it to ATtiny...
Logged

-Arne

Offline Offline
Jr. Member
**
Karma: 1
Posts: 85
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Im using an ATtiny85 (sorry I didnt put it in the fist post).

I figured out that the compass uses I2C to communicate with the Arduino.
The Arduino has hardware support for I2C and therefore it must be the A4 and A5 pins.

I just found out that there is an I2C library for the ATtiny and I will try if it works.
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The attiny85 has USI also
USI is Universal Serial Interface.
How this is done is beyond me but I'd like to know how you got on?

Page  http://www.arduino.cc/playground/Code/USIi2c
Extract 
I2C (master and slave) on the ATtiny85
Overview:

The ATtiny85 microprocessor is an 8 pin chip with 6 (max!) I/O ports. Using an I2C bus greatly expands the possibilities of what you can do with this chip.

The ATtiny85 (and it's cousins) does not have I2C (or SPI) "built in". Instead it has a Universal Serial Interface (USI) that can be used to facilitate I2C and SPI.

After a bit of searching, I found 2 sets of code that use the USI for I2C - one for I2C master and the other for I2C slave. I wrapped each in a separate class and had them follow a similar usage as the Wire lib.
« Last Edit: October 25, 2012, 06:17:34 pm by april » Logged

Pages: [1]   Go Up
Jump to: