Which ATmega do i go with?


  • Hardware Contributor

    Good evening,

    I'm in the process of creating a custom PCB for a light switch and temperature sensor on the board to monitor internal temperature inside of the light switch socket to then maybe trigger an auto shutdown at a certain temp (assuming it would be getting close to catching fire, for some unknown reason). I was looking at the ATmega range of chips from atmel, should i be looking at anything else other than the pin count and the flash size that could limit me? I'm trying to go as small as possible to allow me to fit this behind a light switch and therefor i don't want to increase the size of the PCB because of the chip size if i didn't need to do so. I've just done a quick compile of the switch sketch here and its coming to the following:

    Sketch uses 13,356 bytes (5%) of program storage space. Maximum is 253,952 bytes.
    Global variables use 410 bytes (5%) of dynamic memory, leaving 7,782 bytes for local variables. Maximum is 8,192 bytes.
    

    Now, that doesn't include anything for the temperature sensor that i plan on including with the board. But i'm assuming that wont take up much space. So at the moment its looking to come out at around 13.3KB. I'm going to over compensate and say with any temperature reading on that sketch would make it to around the 20KB mark. But please correct me if you know any differently.

    Could anyone just point out what i need to be looking at in terms of specs for the chip itself other than just the memory size, and the amount of pins it has. It must transmit over an RF24l01 module too, hence why I'm looking at the amount of pins.

    Thanks, Sam.


  • Admin

    go with an atmega328p, as that is the most widely supported mcu for arduino.

    Unless you are very adventurous and go with something like atmel SAMD2x MCU. But we are just getting support into mysensors library for that one.


  • Hardware Contributor

    @tbowmo I'm currently sketching, documenting and pretty much settling on the 328p tbh, from reading the datasheets, looking at nanos that i currently have and the pinouts, they look a pretty nice little chip. I'm just adding a 16MHz crystal to my schematics, the very few caps, the RF module and the switch plate and i think i'm pretty much there for drafting it up. Then I'll move onto the detailed schematics and maybe a board preview and I'll post it up on my 'build log' for people's opinions.

    So just quickly, what do i need for a very basic arduino board? Currently I have:

    • list itemATmega328p

    • list item16MHz crystal

    • list item2 caps for the crystal

    • Some form of serial connection to upload the bootloader and sketches.

    That is all i have for the arduino section itself, then i will add the battery connection, the RF module and the switch plate. Am i missing anything obvious in your opinion?

    Thanks, Sam.


  • Admin

    You don't need the crystal, there is an internal 8mhz RC oscillator available.

    I would recommend to take a look at the sensebender, it's as basic as it can be (just remove sensor / flash / atsha204 if you don't need those)


  • Hardware Contributor

    @tbowmo I've been reading that if i use a 8MHz oscillator (added on, or built in) it could potentially through a few things out of sync including the uploading of the sketch. Also, it stated that it would then take the microcontroller twice as long to perform the tasks. As an example they said that if you put the board to sleep for 9ms and had it performing a task for 1ms every 10ms using a 16MHz crystal that is fine, but if you use a 8MHz it would then make the board sleep for 8ms and perform that task for 2ms, so in some instances it would end up in more power draw over a given length of time.

    Also, after thinking about the flash situation, because this is going to be a battery operated node, i would need some flash memory to hold the sketch in between uploading the sketch and powering the device on with the battery, and when i come to change the battery it would lose the sketch if i didn't have any flash. Am i correct in saying this?


  • Admin

    @samuel235

    Running higher frequency will use more current.. In theory keep your oscillator frequency as low as possible. Also you should have a look at how often you want to report the temperature. Normal temperature sketches are measuring once every minute (or even less frequently). Then it doesn't matter if it takes 1 mili second, or 2 mili seconds to perform an operation.

    Also, what temperature sensor are you planning to use? If it's digital, your MCU is probably going to wait for the temperature conversion etc.. anyways, (which can be up to several mili seconds). So again, it doesn't matter if the MCU is running 8 or 16Mhz.

    Another point, is that for running 16Mhz, you need to supply the atmega328p with 5V, as it's not rated for running 16Mhz at 3V (or lower). That means you need to have a "5V battery" (stepup or the like). in order to get it running at 5V.

    Now for the external flash, and bootloader support. There are two bootloaders available for OTA FW upgrades.

    • MysBootloader - no external flash needed, but only supports NRF24, and no security features (signing etc.)
    • DualOptiboot - needs external flash to store fw while uploading it. Supporting both NRF24 and RFM69 radios, and supports signing (dev branch of Mysensors library is probably needed)

    If you use MysBootloader, it doesn't loose firmware if it looses power. Firmware is still stored in internal flash on the MCU, but the node will not function normally while uploading a new sketch, as it's in bootloader mode. While using DualOptiboot / external flash, node will continue to work with the old sketch, untill the new sketch is uploaded to the node (external flash) and verified, after which the content of the external flash will be moved to internal MCU flash and executed.


  • Hardware Contributor

    @tbowmo First of all - Thank you for such an in depth answer and explanation, the reason i turn to the forums to ask questions is not because i was swift, short and straight to the point answers, its because i'm actually interested in learning along the way. A true maker enjoys the build as much as the end product πŸ˜‰

    So, after your advice on the crystal i think i will go ahead and use the on board clock for the 8MHz oscillator. The idea of the Dallas DS18B20 temperature sensor that i was going to have soldered onto the board was simply to monitor the temperature of the this board inside of the switch socket (this whole board will be located behind a wall switch, hence the need for a ultra small custom pcb). I wasn't going to get this information to be sent to the controller, i was hoping to figure out a way to auto switch off the node if it hit a certain temperature, and send a message/alert to the controller before turning off, if possible. However, i'm not considering to send the temp data whenever the switch is used, but that is just an idea (will use the battery a lot quicker than just keeping it internal, so i might not do so). As for the type of the temperature sensor, i'm just assuming i will be using a Dallas DS18B20, but if there is a lower power option out there, i will be sure to use that when i come to ordering the parts.

    I will more than likely be using the MysBootloader as i don't really need any of the options that DualOptiboot offers, i certainly don't need the node to be running the current sketch while i upload a new one, as a switch it wont be used while uploading a new sketch anyway. I have no plans to use this as another node other than a switch either. On the plus side, the MysBootloader will allow me to have a smaller footprint on the PCB too.


  • Hardware Contributor

    hi.

    Maybe you have already thought about this...but if it is batt powered. I guess you will use sleep mode. and maybe wake up on switch contact..but if it sleeps, you won't be able to receive an order from your controller to toggle your light.


  • Hardware Contributor

    @scalz I'm planning on running the bare minimum on this node so it will literally be a switch that sends ON or OFF to the controller to then turn my relay node on or off, this node will not be the actual relay. So in terms of sketches, this will run a version of the 'BinarySwitchSensor', send data to controller which will then send the on of off to my relay node running 'RelayActuator'.

    So this should be fine to be sleeping, until it receives a switch state change. I'm not sure how i would do the temperature cut off if the node was asleep until the switch is used, because i wouldn't be able to say "If the temp hit XΒ°C then send message/alert and turn off" if the node was sleeping.


  • Admin

    @samuel235

    If this is only a node for sending off a switch command, then why bother with temperature monitoring? It will be sleeping all day, until you press that button on it. And afterwards it will be sleeping again until next time you press it again. the MCU will not be generating any heat, and neither would the radio module (as it will be at sleep for most of the time)

    Also, be aware that the DS1820 doesn't operate below 3V, so that also puts some requirements on your supply voltage.


  • Hardware Contributor

    oki I see πŸ˜‰ I am not at my best this morning lol.
    yep, you are right about your sensors and power consumption. keep thing simple to design your board. you will have time then to improve it πŸ˜‰ so sensebender is a great start for what you want to do..

    on my side I am adapting mytinycamel circuit to make a simple batt powered node inwall. but with a shield for sensors..I will show you when finished. it's much more when you need other sensors..because for a switch node, your project is fine πŸ˜ƒ


  • Hardware Contributor

    @tbowmo - I was only having the temp sensor there in case of a irrational/unpredicted sense of events and causes a fire, hoping my theory would make this board over the top safe. However if you feel that there would be no chance what so ever of this happening i will not bother using it.

    On the chip front, would i be better using something smaller/less power hungry since i'm only using a switch and the radio here? I'll stick with the 328-PU if there isn't much power i can reduce it by.

    @scalz - Indeed, like i have said before, i love the look of your 'MyTinyCamel' board. I also love the idea of your sensor board in the wall too, this will be my next application, however I wanted to design this for the cases where you are very limited on space inside of your wall socket and just needed a switch node. I can only hope to develop our products together at some point in the future πŸ˜‰


  • Hardware Contributor

    😎
    for the chip, I agree with tbowmo. you should use 328p I think. p for picopower (140-200nA max sleeping, on standalone), widely arduino and mysensors used. enough mem to handle mysensors lib, radio..no big surprise.


  • Admin

    @samuel235

    Go with 328p.. you'll only get more problems, if you choose other chips (like the attiny mcus)

    328 is the standard for arduino. Just be sure that you have access to programming (ISP port) pins on the mcu, otherwise you'll have problems in putting in the bootloader.



  • @tbowmo said:

    You don't need the crystal, there is an internal 8mhz RC oscillator available.

    I would recommend to take a look at the sensebender, it's as basic as it can be (just remove sensor / flash / atsha204 if you don't need those)

    How do you programme a factory atmega328p to run on 8mhz internal?


  • Hardware Contributor

    Right, okay. So 328-PU it is. By the way just to let you know i was looking at the likes of the ATmega8, and others in the mega range. Wasn't bothering with the ATtiny range. But i'll stick with ATmega328-PU. But other than the chip, rf24, the switch and a serial connection for uploading the bootloader and sketch, i don't need anything else to have a functioning 'arduino', right?

    Ill get some more design and schematic work done when i get home from work tonight and get some drafts up on here.


  • Hardware Contributor

    @Mickey said:

    @tbowmo said:

    You don't need the crystal, there is an internal 8mhz RC oscillator available.

    I would recommend to take a look at the sensebender, it's as basic as it can be (just remove sensor / flash / atsha204 if you don't need those)

    How do you programme a factory atmega328p to run on 8mhz internal?

    I have the line of code in my documents at home somewhere, ill post them later if no body provides anything by then. If i can find them that is.


  • Admin

    @Mickey

    By default the atmega328p is running from the internal 8Mhz oscillator, but with clkdiv8 enabled, so that it runs at 1Mhz. For running it at 8Mhz you have to set the fuses and disable the clkdiv8. I'm using the following avrdude command to set fuses with my jtagice3 programmer in an atmega328p

    avrdude -c jtag3isp -p m328p\
    -U lfuse:w:0xE2:m \
    -U hfuse:w:0xD2:m \
    -U efuse:w:0xFE:m \
    -U lock:w:0xEF:m 
    

    change above to use the programmer that you have



  • @tbowmo said:

    @Mickey

    By default the atmega328p is running from the internal 8Mhz oscillator, but with clkdiv8 enabled, so that it runs at 1Mhz. For running it at 8Mhz you have to set the fuses and disable the clkdiv8. I'm using the following avrdude command to set fuses with my jtagice3 programmer in an atmega328p

    avrdude -c jtag3isp -p m328p\
    -U lfuse:w:0xE2:m \
    -U hfuse:w:0xD2:m \
    -U efuse:w:0xFE:m \
    -U lock:w:0xEF:m 
    

    change above to use the programmer that you have

    So if my current fuses are like this:
    virginfuses.png
    can I still communicate with the chip with usbasp without external crystal?


  • Hardware Contributor

    @tbowmo said:

    Now for the external flash, and bootloader support. There are two bootloaders available for OTA FW upgrades.

    • MysBootloader - no external flash needed, but only supports NRF24, and no security features (signing etc.)
    • DualOptiboot - needs external flash to store fw while uploading it. Supporting both NRF24 and RFM69 radios, and supports signing (dev branch of Mysensors library is probably needed)

    Without using external flash could i use the Arduino bootloader? Did you only mention these 2 for their "OTA Firmware upgrade" ability? I'm struggling to workout how to burn this MysBootloader onto my chip. I can't find much information on this.

    EDIT: So, I've been reading on the Google Docs for bootloading, and it would appear all that i have to do is put the MysBootloader sub-folder into the bootloaders folder in my Arduino IDE documents. So, i have done that but i still only have "Burn Bootloader" in the tools drop down menu, is this normal not to be able to choose which bootloader i would like to burn or do i need to have my board plugged into my computer to then be recognised to be able to burn MYSBootloader?


  • Hardware Contributor

    And which way is your/the preferred method of burning the bootloader, would you use a Arduino Uno and burn the bootloader using the "Arduino as ISP" option or would you go with something like a USBtinyISP adapter? Could you provide a link for a specific programmer if you use one as I'm seeing a lot of varying types/sizes/shapes and I'de like a recommendation of a working device from someone that uses one. If you use an Arduino UNO, i will just purchase one of those instead.


  • Admin

    @samuel235 Please follow these instructions for burning MYSBootloader and testing OTA updates with MYSController. Both, USBasp and ArudinoISP are easy to use as long as you do not mix up the cables...


  • Hardware Contributor

    @tekka - How on earth did i not stumble across this! Thank you very much! I will get ordering myself an UNO in preperation to getting my board manufactured. Now i know which connections are needed in my ISP header, i will carry on sketching out the schematic. Thank you once again!


  • Admin

    @samuel235

    I'm using genuine atmel programmers (currently I'm on jtagice3) been serving me fine for the last couple of years (also have the added benefits of being able to work together with gdb, so I can debug arduino code on my atmel sam D21 mcu)

    Anyways, there are lot's of (cheaper) programmers out there, amongst others you could use another arduino as programmer..



Suggested Topics

58
Online

11.4k
Users

11.1k
Topics

112.7k
Posts