Showing posts with label ATmega328P. Show all posts
Showing posts with label ATmega328P. Show all posts

Friday, May 27, 2016

Pull-up and Pull-down Resistor Tutorial

In this post we take a look at what are pull-up and pull-down resistors, their purpose, and where to use them.



Arduino code from video:
void setup() {
  // put your setup code here, to run once:
  pinMode(3,INPUT);
  pinMode(6,INPUT_PULLUP);
  pinMode(5,INPUT);
  pinMode(4,INPUT);
  pinMode(2,INPUT);
  Serial.begin(57600);

}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print("This is the pull-up input D6 ");
  Serial.println(digitalRead(6));
  Serial.print("D5 input has no pull-up ");
  Serial.println(digitalRead(5));
   Serial.print("D4 input has no pull-up ");
  Serial.println(digitalRead(4));
  Serial.print("D3 input has no pull-up ");
  Serial.println(digitalRead(3));
   Serial.print("D2 input has no pull-up ");
  Serial.println(digitalRead(2));
  Serial.println();
  delay(1500);
}

Tuesday, March 15, 2016

Building a Wireless Sensor Network with the nRF24L01 Part 5

In Part 5 of building a wireless sensor network with Arduino and the nRF24L01+ transceiver we take a look at our brand new PCB boards and look at the code for adding the DS18S20 and the STTS751 temperature sensors to the design. You can access the PCB Eagle files and the Arduino code from GitHub: https://github.com/ForceTronics/nRF24L01_Wireless_Sensor_Dev_Board






Monday, February 8, 2016

The Watchdog Timer on Arduino

In this video we take a look at the Watchdog Timer on Arduino and the three different ways to configure it. We show a simple example using the Watchdog Timer and you can find the code from the example below.



//**********************Arduino Code*******************************
#include <avr/wdt.h> //Watch dog timer functions
#include <EEPROM.h> //library for using EEPROM

// Pin 13 has an LED connected on most Arduino boards.
int led = 13;
volatile int wSetting = 1; //variable to store WDT setting, make it volatile since it will be used in ISR

void setup() {
  wdt_disable(); //Datasheet recommends disabling WDT right away in case of low probabibliy event
  pinMode(led, OUTPUT); //set up the LED pin to output
  pinMode(2,INPUT_PULLUP); //setup pin 2 for input since we will be using it with our button
  getSettings(); //start serial settings menu to choose WDT setting
  //setup the watchdog Timer based on the setting
  if(wSetting == 1) setWDT(0b01000000); //set for interrupt
  else if(wSetting == 2) setWDT(0b00001000); //set for reset
  else setWDT(0b01001000); //set for interrupt and then reset
}

void loop() {
  
  if(!digitalRead(2)) { //check if button to reset WDT was pressed
    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    wdt_reset(); //Reset the WDT 
  }
}

//This function gets the WDT setting from the user using Serial comm
void getSettings() {
  Serial.begin(57600);
  Serial.println("We just started up......");
  byte b; //variable to store interrupt / reset tracker
  if(EEPROM.get(10, b)) { //check if interrupt occurred before reset
    Serial.println("...and an interrupt occurred.....");
    b = 0; //reset variable
    EEPROM.put(10,b);
  }
  Serial.println("Select the WDT setting: 1 --> interrupt, 2 --> reset, 3 --> interrupt and reset");
  //wait for user to input setting selection
  while (!Serial.available()) { }
  wSetting = Serial.parseInt(); //get entry and ensure it is valid
  if(wSetting < 1 || wSetting > 3) {
      wSetting = 1;
   }
   Serial.print("WDT setting is ");
   Serial.println(wSetting);
   Serial.println();
   Serial.end(); //don't want to mix serial comm and interrupts together
}

/*
void setSleepInterval(byte timer) {
  sleep_enable(); //enable the sleep mode
  set_sleep_mode(SLEEP_MODE_PWR_DOWN); //set the type of sleep mode. Default is Idle. power down saves the most power
  ADCSRA &= ~(1<<ADEN); //Turn off ADC before going to sleep (set ADEN bit to 0). this saves even more power
  WDTCSR |= 0b00011000;    //Set the WDE bit and then clear it when set the prescaler, WDCE bit must be set if changing WDE bit   
  WDTCSR = 0b01000000 | timer; //This sets the WDT to the interval specified in the function argument
  wdt_reset(); //Reset the WDT 
  sleep_cpu(); //enter sleep mode. Next code that will be executed is the ISR when interrupt wakes Arduino from sleep
  sleep_disable(); //disable sleep mode
  ADCSRA |= (1<<ADEN); //Turn the ADC back on
}*/

//this function setups up and starts the watchdog timer
void setWDT(byte sWDT) {
   WDTCSR |= 0b00011000;
   WDTCSR = sWDT |  WDTO_2S; //Set WDT based user setting and for 2 second interval
   wdt_reset();
}


//This is the interrupt service routine for the WDT. It is called when the WDT times out and is in interrupt mode. 
//This ISR must be in your Arduino sketch or else the WDT will not work correctly
ISR (WDT_vect) 
{
  digitalWrite(led, HIGH); 
  if(wSetting == 3) {
    byte b = 1;
    EEPROM.put(10, b);
  }
  //wdt_disable();
}  // end of WDT_vect

Wednesday, January 6, 2016

Building a Wireless Sensor Network with the nRF24L01 Part 3

In part three we take a look at the updated hardware schematic of the router / end device design, how the router / end device settings work, and we go over the initial software of the router / end device. You can find the code from this video in GitHub at https://github.com/ForceTronics/nRF24L01_Wireless_Sensor_Dev_Board


Monday, December 7, 2015

Building a Wireless Sensor Network with the nRF24L01 Part 1

This is part 1 in a series where we look at how to build a large wireless network using Arduino and the nRF24L01+ Transceiver Modules. At the end of this series you will have a reference design for a wireless sensor development board and the code needed to turn the wireless sensor developments boards into a network. You will be able purchase all the hardware for this project at my site: www.forcetronics.com


Initial Hardware Design

Friday, October 30, 2015

Building a Arduino Uno Compatible Circuit

Ever want to remove the microcontroller off the Arduino board to better integrate it into your project or design. In this video we do just that with Atmel ATmega 328P MCU found on the Arduino Uno. We will look at the bare bones circuit setup needed to run the 328P as well as how to still program it with the Arduino IDE. All the parts shown in this video can be purchased from forcetronics.com.