Some Sensors Using ATMega32-16AU

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

Hi guys! I did flight controller for our rocket team “Aphelion”. I used ATMega32-16AU for microcontroller unit. My problem is, actually i did not use sensors or modules without Arduino IDE.

I have problem with this sensors:
- MCP9808
- MPL3115A2
- ADXL345
- MPU9250

I can not find any example codes of this sensors for ATMega32 AVR. How can i write codes for this sensors? Can i integrate arduino codes or libs etc.? Thanks a lot.

Attachment(s): 

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

The Arduino codes will work just as well without the Arduino IDE. I think there is an Arduino core for the mega32, so that should go some way to solving your problem. But why use the old mega32?

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


dh1p-dev wrote:
How can i write codes for this sensors?

How to interface anything to anything elsehttp://www.8052mcu.com/forum/read/160143

 

See Tip #1 in my signature, below, for how to put the pictures in your post - where we can see them:

 

 

 

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

Thanks for answer. What do you mean with ardunio core? Is it same with Burning arduino bootloader?
I used atmega32-16au but i did not know it is old. Actually Altium indicates warning about this but i did not understand why it is old.

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

Thanks for forum tips and links. I’am looking the link which you send at the moment.

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

Google arduino core mega32

You’ve designed a pcb andit looks like you have not followed the manufacturer’s recommendations, you've chosen a chip that is old and probably unsuitable as i can see a sd card socket - a mega32 does not have much ram and you’re asking how to drive common peripherals. Should you have not resolved the last items first?
Also, if this board is to travel on a rocket, have you considered the effects of large accelerations on the components you’ve chosen? Eg the crystal and electrolytic caps?

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


MightyCore supports the legacy Mega's here: https://github.com/MCUdude/Might...

There are instructions there to tell you how to install this, very easy to do and opens a lot of libraries to these older mega's.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Thu. Jul 30, 2020 - 12:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Actually, it is my first PCB design and other processes. I did not write code for avr without Arduino bootloader ever. Actually, i used Arduino since 2 months ago. And then i said myself to, why you are learning just Arduino for 2 years. It is my and my teammates’’ educational journey to embedded systems. I will be really happy if you tell me my mistakes about this card or recammendations. So yes, you are right i have a lot of mistake for this board. Our rocket will flight 1 month after and i am working for getting data from sensors.

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

It sounds awesome! Is it neccessary burn arduino bootloader for this?

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

No. The bootloader is purely for convenience.

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

Oh! I will try this method. So, i can do this with no bootloader like factory new atmega32-16au, thanks a lot i hope this method will work.

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

Cool project, by the way, hope it works well for you.

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Thanks a lot for your kindly comment, i love doing projects for learning and improve myself!

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

dh1p-dev wrote:
I have problem with this sensors:
- MCP9808

https://learn.adafruit.com/adafr...

Adafruit has demo code you can use

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

dh1p-dev wrote:
MPL3115A2

Sparkfun has code for this sensor: https://learn.sparkfun.com/tutor...

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

dh1p-dev wrote:
ADXL345

Sparkfun has this one too: https://learn.sparkfun.com/tutor...

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

dh1p-dev wrote:
MPU9250

And this one as well:  https://learn.sparkfun.com/tutor...

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

ki0bk wrote:

dh1p-dev wrote:

ADXL345

 

Sparkfun has this one too: https://learn.sparkfun.com/tutor... 

Just taking this one at random, the manufacturer also has supporting collateral:

 

https://wiki.analog.com/resources/tools-software/uc-drivers/renesas/adxl345

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

Thanks for your answers, but i guess there are arduino codes and i do not know how to integrate arduino codes to atmel avr.

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

dh1p-dev wrote:
i guess there are arduino codes

Not the one direct from Analog Devices!

 

 

Quote:
i do not know how to integrate arduino codes to atmel avr.

Eh?

 

Arduino is Atmel AVR !

 

(well, most of them are)

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

Use an Uno to build your sketch, once it is working, rebuild after selecting the mightycore board and upload to your board.

AS7 has a method to import arduino sketches into C++ projects if you must.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

You need to first review how to do I2C interfacing on the Mega32.  It is called Two-Wire Interfacing in the AVR datasheet for Mega32.  All the sensors that you list have this I2C/TWI interfacing.

Basically you set up the TWI peripheral, send a START command, send the Sensor's address, send the starting register that you want to read from the sensor.  Then do a RESTART and read the sensor's registers.

 

Use the Arduino code for the sensors.  But use low level I2C/TWI data read write commands instead of the wire.h library's TransmissionBegin and End commands.  

 

Are you going  to put these sensors into a rocket?

 

 

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

Thanks, i connect my board with ft232 uart to usb module. But Usbasp for Programming. In your way, how can i upload the code?

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

Yes, the photo which i attached is our flight controller board and these sensors sits on this board, but i can not get data because i can not find code examples, i can not integrate arduino codes to my board etc. Actually, you’re right for first thing i should know is using i2c with avr because i am Using i2c for all sensors.

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

dh1p-dev wrote:
In your way, how can i upload the code?

bootloader via the USB/TTL cable.

 

This has the advantage that no programming h/w is needed, and allows program update in the field if needed.

 

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Thu. Jul 30, 2020 - 06:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Do you mean while i try your way, i need burn bootloader to my microcontroller first. Then i can do “MightyCore” with FTDI?

Last Edited: Thu. Jul 30, 2020 - 06:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dh1p-dev wrote:
i need burn bootloader to my microcontroller first. Then i can do “MightyCore” with FTDI?

Yes, once you load MightyCore, it will have the bootloaders you need for your AVR/clock rate combo.   Use Arduino IDE to "burn bootloader".

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Actually, i tried to burn bootloader once. I got error “ Double check connections and try again, or use -F to override this check. Error while burning bootloader.“. But i will try one more. I hope it will works, thanks!

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

Realise that 'Arduino codes' is just C++/C  and Arduino just gives you a selection of functions to do the usual stuff.  The Arduino 'cores' give you the 'usual' stuff for different AVRs (or other microcontrollers). 

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

dh1p-dev wrote:
I got error “Double check connections ...“

So did you do that?

 

Are your connections correct?

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

Absolutely yes, i can upload program with atmel studio over USBasp, but i can not burn Arduino bootloader over arduino ide with same time and same connection.

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

The bootloader has to be one specifically for the atmega32 - burning the uno bootloader is not going to work.

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

Oh, i see. What is your recommendation?

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

Recommendation? Between using a bootloader or isp using the usbasp? Whatever works best for you. The result ends up being they both are means of loading your code.

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

I mean, which bootloader should i burn if i can not burn uno bootloader. I followed same instructions on internet and i got an error while burning bootloader.

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

The bootloader that the megacore for mega32 suggests you use. Saying that you read ‘some instructions on the internet’ tells us very little - try to be a bit more descriptive.

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

ki0bk wrote:
Yes, once you load MightyCore, it will have the bootloaders you need for your AVR/clock rate combo.   Use Arduino IDE to "burn bootloader".

Did you not read this post?

google "arduino mightycore" select first hit, scroll to the bottom of the page and follow the instructions on how to install!

 

Once installed, go to Tools/board/mightycore/Mega32 select

Now look at Tools menu, set clock speed to match your board,

set bod to match what you want,

set pinout, review the mightycore webpage to know how to set these options.

 

Once the board settings match what you want for your board, now you can select burn bootloader using your usbasp!   Enjoy

Now you can load your sketches via the serial adapter using the bootloader you burned above.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

Watch out for microSD card in a card socket in a rocket. You may need to positively secure it. Those vertical card sockets are very tender for sideways forces (I use them in my accelerometer product) I would glue it solidly to the board in this application.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Oh! Thanks a lot, you’re saying because of sd card may fall while flying right?

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

And your crystal. Read the manufacturer's specs to see you don't exceed acceleration etc.

 

And the battery holder - you have a mass supported by a couple of thin pins. Vibration will try to kill it.

Last Edited: Sun. Aug 2, 2020 - 10:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using with 16mHz crystal. But you re right my mistake, i did not read datasheet well. So i will look Fully, two more times. And i guess i should make Battery holder stronger.

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

Not just that the card may fall out. The  socket, itself, is quite weak. Glue it to the board with something strong, like "shoe-goo" or hot-melt adhesive. Apply the adhesive after soldering the socket to the board.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!