Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Copy PORTC to PORTD? on: December 11, 2010, 05:52:17 pm
never mind... I was using PORTC instead of PINC to get data from the C port.  It's working fine now.
2  Forum 2005-2010 (read only) / Syntax & Programs / Copy PORTC to PORTD? on: December 11, 2010, 04:04:15 pm
Hey, guys!
I'm trying to nail down port manipulation.  I've got a workable ten-segment tracer on pins 2-11..

Code:
void setup() {
  DDRD = B11111100;
  DDRB = B00111111;
}

int b[] = { 0, 0, 0, 0, 0, 0, 1, 2, 4, 8 };
int d[] = { 4, 8, 16, 32, 64, 128, 0, 0, 0, 0 };

void loop() {
  for ( int n = 0; n<9; n++ ) {
    PORTD = d[n];
    PORTB = b[n];
    delay (25);
  }
  for ( int n = 9; n>0; n-- ) {
    PORTD = d[n];
    PORTB = b[n];
    delay (25);
  }
}

...and now that I have output handled reasonably well, I'd like to understand input.  I would like to access input through PORTC, and transfer it directly to PORTD as a monitor.  The sensors I am using require the pullup resistors on pins 14-19 (analog 0-5).  This is my straw man:

Code:
void setup() {
  DDRC = B00000000;
  DDRD = B11111100;

  PORTC = B11111100;
}

void loop() {
    PORTD = PORTC;
}

...which doesn't work.  I'm sure that my method of turning on the pullup resistors is wrong.  I've also tried digitalwrite on all the pins after setting them to input, but that doesn't work either.  Does it complicate things that these are analog pins?
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial.Read() Variable on: October 29, 2010, 10:30:42 pm
Quote
...the function needs to return a larger value - one that can hold all possible legal values and one or more non-legal values.
...so what's needed is a simple type conversion from a 16-bit signed integer to an 8-bit unsigned byte.  Thank you, Paul, I get that!

This change...
Code:
PORTD = byte(Serial.read()) << 2;
...causes the Arduino to react.

A new problem is that the other two bits are coming up on the wrong pins.  ( the other four, actually )  Maybe the type conversion isn't right?  I'll keep reading, but do you have any ideas?


Update:  I'm sending 0 to 255 and the Arduino is counting to 10 over and over.
Update update:  It's on the Perl side.  The Arduino monitor yields perfect results.  Thanks for your help with Arduino, Paul!
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial.Read() Variable on: October 29, 2010, 07:37:24 pm
I'm sorry, let me start again.

I have a Perl script sending integers to the Arduino at half-second intervals:

Code:
use Device::SerialPort;

my $port = Device::SerialPort->new("/dev/ttyUSB0");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);

while (1) {
@array = ( 4, 8, 16, 32, 64, 128 );
      for $n (0..$#array) {
            $port->write("$array[$n]");
            print "Sent: $array[$n] \n";
            select(undef, undef, undef, .5);
      }
}

Then I have the Arduino taking the serial input an assigning it to the PORTD register (with RX and TX masked, of course):

Code:
void setup()
{
  DDRD = DDRD | B11111100;
  Serial.begin(9600);
}

void loop()
{
  while (Serial.available() > 0) {
          PORTD = Serial.read();
          }
}

...but this isn't working.

I'm still new with Arduino, and very new at serial communication.  I was trying to get a clue, and several examples seem typical of the "Physical Pixel" example that comes with Arduino:

Code:
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') {
      digitalWrite(ledPin, HIGH);
    }
    // if it's an L (ASCII 76) turn off the LED:
    if (incomingByte == 'L') {
      digitalWrite(ledPin, LOW);
    }
  }
}

The variable that receives the return value of the Serial.read() function is initialized as an int...
Code:
int incomingByte;      // a variable to read incoming serial data into
...and seems to be handled like a char...
Code:
   if (incomingByte == 'H') {
Code:
   if (incomingByte == 'L') {
(I used the above Perl script to send a capital 'H' or 'L' to the Arduino, and it works fine.)
Anyway, there appears to be a type mismatch in the code.

I looked at the documentation and a dozen other pages to try to get an answer before coming here, but I'm snagged on this point.

What is the paradigm with the Arduino serial?
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial.Read() Variable on: October 29, 2010, 02:11:36 pm
I've read stuff.  Specific link, please?
6  Forum 2005-2010 (read only) / Syntax & Programs / Serial.Read() Variable on: October 29, 2010, 11:56:50 am
Hi, evrybody!
  I have been working with Arduino for a little while, now, and I have a project that requires information to go from the computer to the microcontroller.  As an excersize, I tried just dropping the return value for Serial.Read() into the PORTD register, but that doesn't work.  After looking a bit closer at the examples, it seems that the variable that holds the return value is initialized as an 'int', but handled like a 'char'.  What's going on?

Thanks
7  Forum 2005-2010 (read only) / Development / MEGA-ISP limits? on: November 17, 2010, 09:42:50 pm
I was reading that MEGA-ISP is used to burn the bootloader onto a new chip.  Can it be used with the IDE to burn an arbitrary sketch onto any arbitrary chip?  I'm sure there are limits, but what are they?  Are we limited to Arduino-compatible chips?  Can the IDE compile for (e.g.) attiny?
8  Forum 2005-2010 (read only) / Development / Re: direct PWM on: September 11, 2010, 03:33:51 pm
Quote
Also note, particularly, that Timer0 is used for millis() and delay() functions, so using Timer0 for PWM may require some care (or else...)

Yeah, I had read that PWM might not shut off completely under certain conditions associated with delay instructions.  I need to control some H-bridges that carry several amps, so that kind of made me anxious.  I won't need to delay or time anything, though.  If I don't use any delay() or millis(), will that get rid of the complications?
9  Forum 2005-2010 (read only) / Development / Re: direct PWM on: September 11, 2010, 03:20:54 pm
I'm rather new to microcontrollers in earnest.  I'm kind of pressed for time on a project and I'm wondering, can this be effectively done within the Arduino IDE, should I take up ASM, or should I just do bona fide GCC?  What are the options with Linux (Ubuntu) (which I am also fairly new to)?
10  Forum 2005-2010 (read only) / Development / direct PWM on: September 11, 2010, 02:22:10 pm
Hey, guys!
  Does anybody know which registers to use for PWM through direct port manipulation?  Are any tricks to doing it this way?
11  Forum 2005-2010 (read only) / Development / Re: direct manipulation pins on: September 11, 2010, 05:24:28 pm
Quote
if (PINB & (1<<6)) {

I wouldn't have thought to do it in that particular way.  Thanks!   smiley
12  Forum 2005-2010 (read only) / Development / direct manipulation pins on: September 11, 2010, 02:56:01 pm
When doing direct port manipulation, is it better to access the (e.g.) PORTB6 register, or is it better to access the PORTB register and do bitwise operators to read bit 6?  Which is faster?
13  Forum 2005-2010 (read only) / Interfacing / Re: yet another photo inturruptor on: September 13, 2010, 10:19:23 pm
It works.
Ok, I thought I had tried that and it didn't work the first time.  Honest, I'm not retarded.

Thanks
14  Forum 2005-2010 (read only) / Interfacing / yet another photo inturruptor on: September 13, 2010, 08:39:10 pm
Hello!
How would I hook this up?

http://www.datasheetcatalog.org/datasheet/fairchild/QVE00112.pdf

I feel dumb, it seems like a no-brainer.  Is it on par with the "Button" thing?
15  Forum 2005-2010 (read only) / Interfacing / Re: input/output - need pullups? on: September 12, 2010, 11:38:10 pm
Quote
While we are happy that you have it working, it would have been nice to let us (and future searchers) what was wrong and how you fixed it. It might help someone who comes after you.

That is selfish of me, I'm sorry.

Well, like the "Button" page says, the input will float all over unless you nail it directly to ground with a 10k pull-down resister.  Then you just feed your input 5v to make it go high.  The resistor keeps the 5v from shorting directly to ground.

One typical noobish brain toot after another.  I just wasn't getting it until I found that particular page.
Pages: [1] 2