Questions About Connecting an Accelerometer to an Attiny104

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

Hi all,

 

I'd like to connect a Dev-11055 IMU to an Attiny 104, more just to practice connecting peripherals, and I have a few questions. 

(Here's Sparkfun's order page for the Dev-11055: https://www.sparkfun.com/product...)

 

My first question is, after I connect it to my Attiny104, can I program this in Atmel Studio 7? It looks like the Dev-11055 is geared more towards programming in the Arduino IDE. (It uses an Atmega328p chip.) My hunch is that that's if I were to use the IMU and nothing else.

 

The other question I have is, it's got TX/RX pins, pins like MISO/MOSI for SPI, and SDA/SCL for I2C. Are those each options of how I could 'interface' it with the Attiny104?

 

And lastly, let's say it was connected with UART or SPI with the Attiny104. How would I go about sending it commands like "send the X data for the accelerometer, and not the gyroscope", or "send the z data for the gyroscope"? Does it work like me sending it commands to set bits and then read bits in the IMU's registers through the Attiny104 as if I was just accessing the 104's built-in peripherals? I definitely know I'll have to do some datasheet sifting, but it's the big picture of working with an external device that I'm curious about right now.

 

Thanks

Last Edited: Mon. Jun 19, 2017 - 06:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does the Dev-1105 board have a Mega328? If so, there is no reason in the world to try to use a Tiny104 to "drive" it. Or, are you talking about an Arduino that it is designed to interface to?

 

Just looked at the Sparkfun web page. It looks like it is designed to behave (and be programmed like) an Arduino. As I suggested, Tiny104 is a bit of nonsense. It looks like you can interface it to the outside world using UART or I2C or SPI, just like a regular Arduino.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Mon. Jun 19, 2017 - 06:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It has its own Atmega328. I definitely see what you mean, as it would be a pain in the a** to 'drive' it with the Attiny104. But could you? haha. And if so how?

 

The reason I ask is because I'll have ordered an external ADC and DAC by next week, and I want to get some practice at interfacing with SPI.

Last Edited: Mon. Jun 19, 2017 - 06:39 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok thanks for the information.

 

Let's say I wanted to make things hard for myself and read it through the 104 with SPI. Would I be correct in thinking about the process as:

1. Program the Dev-11055 in the Arduino IDE, and set it to sending let's say x-data for acceleration to its MISO pin

2. Hook up the 104's MOSI to the Dev's MISO pin (along with the other lines)

3. and then do the bit-trading operations to obtain the data?

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

Yes. One minor detail, however: with SPI, the  slave does not offer data. The master says "give it to me now" and the slave has to do it, now. So, the usual process is for the slave to notify the master with an interrupt line. By pulsing that line, the slave says "hey, I have new data, and its ready for you now". Once the master recognizes that pulse, it then requests the data from the slave. It is common to use an interrupt input on the master to listen for this "new data alert". It can come from any (otherwise unused) pin on the slave.

 

OR, you can turn it around and make the M328 to be the master and the T104 be the slave. Then, you don't need that alert interrupt.

 

Hope this helps,

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Mon. Jun 19, 2017 - 07:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

daisy148 wrote:
SPI with the Attiny104. How would I go about sending it commands like "send the X data for the accelerometer, and not the gyroscope", or "send the z data for the gyroscope"?

 

from MPU6000 datasheet:

 

SPI Operational Features

1. Data is delivered MSB first and LSB last
2. Data is latched on the rising edge of SCLK
3. Data should be transitioned on the falling edge of SCLK
4. The maximum frequency of SCLK is 1MHz
5. SPI read and write operations are completed in 16 or more clock cycles (two or more bytes). The
first byte contains the SPI Address, and the following byte(s) contain(s) the SPI data. The first
bit of the first byte contains the Read/Write bit and indicates the Read (1) or Write (0) operation.

The following 7 bits contain the Register Address. In cases of multiple-byte Read/Writes, data is
two or more bytes:

SPI Address format
MSB                              LSB
R/W A6 A5 A4 A3 A2 A1 A0

SPI Data format
MSB                              LSB
D7 D6 D5 D4 D3 D2 D1 D0

6. Supports Single or Burst Read/Writes.

 

No further explanation for register accessing (address / data) ?

 

 

ATtiny 104:

 

– 1024 Bytes of In-system Programmable Flash Program Memory
– 32 Bytes Internal SRAM

– In-system Programmable
   • External Programming over TPI (2.7 – 5.5V)
   • Self Programming (1.8 – 5.5V)

 

 

Well... happy coding... :)

 

 

I don't know why I'm still doing this hobby

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

"1. Program the Dev-11055 in the Arduino IDE"

 

I hope I do not make misunderstanding, but the Dev11055 is already programmed (links accelero/compass/pressure sensor to I2C or SPI, according to pins setting -choosing between I2C and SPI- and orders sent from an I2C/SPI master -which can be an arduino-

 

Instead of reprogramming the SPI (which would at least double your work -it would "only" double if you know you can code one part without any error, and which side-...), you should keep it as is and try to decode/display its informations pn another micro.... Perhaps you shopuld, at least to begin, with a micro which has "lot" of processing capacities...

 

Other issue I see :

trying to scale/convert/display -on seril line, in ASCII the values of a 3 axis accelerometer (I decided to avoid floating, which might be more RAM/flesh consuming) would need (I give each of them 4 bytes for a string conversion; a raw value is 2 bytes; I assume you need 2 other bytes for scaling =8) 8*3 24 bytes... Remain 8 bytes for the stack, which is very tiny...

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

Thanks for picking out that information!

 

In that case, would I be correct in thinking of it as:

1. Trade one byte for read/write info and address info

2. One byte for the low SPI data (for 16 bits)

3. One byte for the high SPI data

in a sort of interrupt loop like Jim was saying?

Last Edited: Mon. Jun 19, 2017 - 04:21 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think you're probably right about it already being programmed. Good point - I'll look into the data sheet for the specifications.

 

For scaling, I'm a bit confused by what you mean by "2 other bytes for scaling = 8". Would you mind explaining what that is for, and how it ties into the SPI importing process. Thanks

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

That's great thanks. I didn't know about using it with interrupts.

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

I'll look into the data sheet for the specifications.

Well, I could not find a datasheet...You have a datsheet for each and every ingredient, but (from the link you gave) one does not know  whether there is a datasheet for the data coming into/from  the  connectors (you can get an idea by reading the source.... but it would be far more comfortable if you had specifications).

 

w/r scaling : accelerations are given in ms-2 officially, but you might prefer ft s-2 or g or 1000 *g; your accelerometer gives you, somehow, rawdata in arbitrary units and it might be comfortable to choose a unit you can read without mental calculations (1000 g is easy to read, and, with a factory trimmed 3D-accelerometer, it is the norm of the acceleration sqrt(acc.x**2 + acc.y**2 + acc.z **2) should be 1000 with a non moving accelerometer.... -> scaling means "to have comfortable units when displaying"

Oh, I forgot there is a 3D compass, too....  Well, just displaying in ASCII  would eat 48 bytes ... perhaps 36 , if you do like raw values.... out of 32 bytes.

Edited : forgot there is a gyrometer, too (storing all these data in 32 bits RAM is getting very complicated .... )

-> you really should use a bigger MCU, at least to test, and perhaps simpler SPI peripherals (if you want to learn, you should begin with very simple things.... if you want to sell a ArduIMU v3 base equipment, sparkfun says it is discontinued...)http://www.gammon.com.au/forum/?... gives you a lot of explanations and slaves you know what they will answer : you just have to concentrate on interconnection and testing....

 

 

 

Last Edited: Mon. Jun 19, 2017 - 05:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you're using an ATtiny104, the best way to interface with the Dev-11055 would be through UART serial since the tiny104 has this peripheral built in.  The other two interface formats: I2C and SPI would be difficult to implement because you would have to do "bit-banging" with precise timing.

 

I assume that the DEV-11055 has the Mega328x to implement a set of common interfaces <USART, I2C, and SPI>  and to let the designer pick one.  It also would do minimal processing on the all the data that comes out of the gyro-accello-magnometer combination.  IIRC the MPU-6000 MEMS 3-axis gyro uses analog voltage outputs and the HMC-5883L uses I2C.

 

The big disadvantage to using the tiny104 is that it is too small in program memory size to DO anything with the masses of data that these MEMS devices generate.

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

MPU 6000 uses both SPI and I2C....