Pages: [1]   Go Down
Author Topic: How disable serial communication pins 0 & 1  (Read 1060 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,

From the following code you will see that I am trying to use PWM on pins 0 & 1 on an Arduino Mega 2560, which I think is possible as long as they are not used for Tx and Rx. I know that communication is required for uploading the code but after that point there is nothing in my code that is a serial function. How can I disable Tx and Rx so I can use PWM on pins 0 & 1?

Code:
void setup () {
 
  for (int motorA = 22; motorA < 37; motorA++) {
    pinMode (motorA, OUTPUT);
  }
  for (int motorB = 37; motorB < 54; motorB++) {
    pinMode (motorB, OUTPUT);
  }
  for (int motorPWM = 0; motorPWM < 14; motorPWM++) {
    pinMode (motorPWM, OUTPUT);
   
       
  }
}




void loop () {
 
  for (int motorA = 22; motorA < 37; motorA++) {
    digitalWrite(motorA, HIGH);
  }
 
  for (int motorB = 37; motorB < 54; motorB++) {
    digitalWrite(motorB, LOW); }
   

 for (int motorPWM = 0; motorPWM <= 14; motorPWM++) {
    analogWrite(motorPWM, 5);

}

Many thanks,

Pete
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What makes you think you can do PWM on Pins 0 and 1?

From Variants/Mega/pins_Arduino.h:
Code:
...
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
// TIMERS
// -------------------------------------------
NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX
NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX
TIMER3B , // PE 4 ** 2 ** PWM2
TIMER3C , // PE 5 ** 3 ** PWM3
TIMER0B , // PG 5 ** 4 ** PWM4
TIMER3A , // PE 3 ** 5 ** PWM5
TIMER4A , // PH 3 ** 6 ** PWM6
TIMER4B , // PH 4 ** 7 ** PWM7
TIMER4C , // PH 5 ** 8 ** PWM8
TIMER2B , // PH 6 ** 9 ** PWM9
TIMER2A , // PB 4 ** 10 ** PWM10
TIMER1A , // PB 5 ** 11 ** PWM11
TIMER1B , // PB 6 ** 12 ** PWM12
TIMER0A , // PB 7 ** 13 ** PWM13
...

From http://arduino.cc/en/Reference/AnalogWrite

Quote
On most Arduino boards (those with the ATmega168 or ATmega328), this function works on pins 3, 5, 6, 9, 10, and 11. On the Arduino Mega, it works on pins 2 through 13.
« Last Edit: August 25, 2012, 05:30:37 am by dxw00d » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34118
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am trying to use PWM on pins 0 & 1 on an Arduino Mega 2560, which I think is possible as long as they are not used for Tx and Rx
Wrong!
A PWM output is linked in hardware to the timers. There is no timer that is linked to these pins.
Logged

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

You can bitbang on those pins only
Logged

Pages: [1]   Go Up
Jump to: