Show Posts
Pages: [1] 2 3 ... 5
1  Topics / Device Hacking / MDB USART mystery on: April 18, 2014, 06:50:18 pm

I have connected an UNO R3 to a circuit desribed in the NAMA MDB 4.2 standard so that I can "talk" to a vending machine.
void init_MDB() {
  // Set baud rate
  // Disable USART rate doubler (arduino bootloader leaves it enabled...)
  UCSR0A &= ~(1 << U2X0);

  // Set asynchronous
  UCSR0C = (0<<UMSEL01)|(0<<UMSEL00);
  // set 1 stop bit
  UCSR0C |= (0<<USBS0);
  // set no parity
  UCSR0C |= (0<<UPM01)|(0<<UPM00);
  // set 9bit
  UCSR0C |=(1<<UCSZ01)|(1<<UCSZ00);
  UCSR0B |= (1<<UCSZ02);

  UCSR0B |= (1<<RXEN0);  // Enable RX
  //UCSR0B |= (1<<TXEN0);  // Enable TX
I can receive data just fine.  When I try to enable transmission
  UCSR0B |= (1<<TXEN0);  // Enable TX
The vending machine goes into "out of service" mode.  I am not sending anything.  The only thing I've done is enable this bit.

Is it possible that the arduino is transmitting and I don't know it?  Maybe TX is set to HIGH or something?

Should I disable TX while I don't need it?

Will toggling it at run time introduce noise to the network and screw things up?

Thank you.
2  Products / Arduino Yún / Re: Yun serial question on: April 16, 2014, 06:30:08 pm
I'm not sure I understand your reply.  Perhaps if I rephrase the question...

I am trying to bridge from my PC to a vending machine with MDB protocol (9 bit parity).  Everyone i've found who has succeeded at this has found hardware serial is the only way to make it work.  I thought a Yun would be convenient - use the hardware serial to talk to the vending machine, and some other serial to talk to the rest of the world.  I thought talking to Yun's linux kernel and then from there to the rest of the network would be pretty straightforward.

Now that I think about it, an UNO with an ethernet shield might also do the trick.

Which method would you suggest?
3  Products / Arduino Yún / Yun serial question on: April 16, 2014, 02:32:18 pm
I'm using the hardware serial in my Arduino to talk to another device.
I need debug messages from the Arduino.  Normally I would Serial.print().
If I use a Yun is there some other way to talk to the linux-side of the board and get my messages out?

4  Using Arduino / Programming Questions / Re: How do I set the frequency on the mega timer3? on: January 06, 2014, 02:26:44 pm
MarkT - I didn't know what the values of CS3* were, so I didn't take the chance.  I'll do it your way.

Have you tried to run it?  Do your results match mine?  I'd love a sanity check to confirm it's not just me getting bad numbers, please.
5  Using Arduino / Programming Questions / How do I set the frequency on the mega timer3? on: January 05, 2014, 04:29:00 pm
I think I've almost got it.  The callback is definitely happening.  The prescalers reported when VERBOSE is defined look good. ...but the frequency actually seen is the same, every time, regardless of the value I ask for.  I think it's the CTC but I'm just not sure.

Please: what did I miss?

Thank you!


void timer_set_frequency(long desired_freq_hz) {
  if(old_feed_rate==desired_freq_hz) return;

  // ** find a valid prescaler **
  // CPU frequency for Arduino is 16Mhz.  CLOCK_FREQ=16000000
  int prescaler_index=-1;
  int prescalers[] = {1,8,64,256,1024};
  // maximum timer counter value (256 for 8bit, 65536 for 16bit timer)
  long counter_value;
  do {
    //  Divide CPU frequency through the choosen prescaler (16000000 / 256 = 62500)
    counter_value = CLOCK_FREQ / prescalers[prescaler_index];
    //  Divide result through the desired frequency (62500 / 2Hz = 31250)
    counter_value /= desired_freq_hz;
    //  Verify counter_value < maximum timer. if fail, choose bigger prescaler.
  } while(counter_value >= MAX_COUNTER && prescaler_index < TIMER_PRESCALER_COUNT );

  if( prescaler_index == TIMER_PRESCALER_COUNT ) {
    // @TODO: Serial.print() from inside the timer interrupt will probably crash the board.
    Serial.println(F("Timer could not be set: Desired frequency out of bounds."));

  // prescalers is zero-indexed, we need one-indexed.

#ifdef VERBOSE
  Serial.print(F("desired_freq_hz="));  Serial.println(desired_freq_hz);
  Serial.print(F("counter_value="));  Serial.println(counter_value);
  Serial.print(F(" prescaler_index="));  Serial.print(prescaler_index);
  Serial.print(F(" > "));  Serial.print(  ((prescaler_index&0x1)   ));
  Serial.print(F("/"));    Serial.print(  ((prescaler_index&0x2)>>1));
  Serial.print(F("/"));    Serial.println(((prescaler_index&0x4)>>2));

  // ** set the timer frequency **

  noInterrupts();  // disable global interrupts
  TCNT3  = 0;  // set the overflow clock to 0
  OCR3A = counter_value - 1;  // set compare match register to desired timer count
  TCCR3A = (1 << WGM32);  // turn on CTC mode
  // Set bits for prescaler
  TCCR3B = ( (( prescaler_index&0x1 )   ) << CS30);
  TCCR3B |= ( (( prescaler_index&0x2 )>>1) << CS31);
  TCCR3B |= ( (( prescaler_index&0x4 )>>2) << CS32);
  TIMSK3 |= (1 << OCIE3A);  // enable timer compare interrupt
  interrupts();  // enable global interrupts
6  Using Arduino / Interfacing w/ Software on the Computer / Persistent arduino/pi connection - how?! on: December 10, 2013, 07:02:04 pm
Challenge: I need a pi to talk to an arduino without resetting the arduino. I have shields on the arduino that prevent me from using a resistor to bridge 5v and gnd.  The shield also blocks my access to RX/TX pins so I can't go use a hardware serial connection with a voltage divider to the pi GPIO pins. Using a daemon on the pi I want to open a connection to the arduino and then keep it open, passing messages back and forth between the arduino and my program.

Method: On the pi side I've got PEAR installed with System_Daemon and php_serial.class.php. I use a mysql db as a 2-way buffer.

Problem: The daemon doesn't appear to be receiving anything from the arduino.  I know the daemon can read and write with mysql.

My daemon code so far:

The error messages:

      err: No stty availible, unable to run. [l:58]
  warning: Specified serial port is not valid [l:141]
  warning: Unable to set the baud rate : the device is either not set or opened [l:234]
  warning: Unable to set parity : the device is either not set or opened [l:288]
  warning: Unable to set length of a character : the device is either not set or opened [l:336]
  warning: Unable to set the length of a stop bit : the device is either not set or opened [l:377]
  warning: Unable to set flow control mode : the device is either not set or opened [l:422]
  warning: The device must be set before to be open [l:167]

stty definitely exists on the pi and can be run as user root or pi, so I don't know why I'm getting error #1dd.

Why is this happening? Is there a better way? Has anyone got a working example?

Thank you!
7  Using Arduino / Programming Questions / Arduino timer1 on MEGA resetting every 4s. What did I do wrong? on: November 03, 2013, 08:15:03 pm

I followed two nearly identical tutorials, one of which is linked in the code.  My board outputs '2hz' and then resets.  I expect it to go through the entire test suite.  What am I doing wrong?  Did I somehow accidentally activate the watchdog?

Thank you!
8  Using Arduino / Installation & Troubleshooting / Yun questions on: September 30, 2013, 03:37:27 pm
can the Yun run a LAMP stack?

can I connect to the Yun Linux via SSH and update the arduino sketch with inotools?

can I send messages from linux to arduino without resetting the arduino?  When I try this from rpi to UNO I need a daemon that keeps the serial connection open and passes messages back and forth using MYSQL as a bi-directional buffer.

Thank you!
9  Using Arduino / Project Guidance / Re: Raspberry Pi + LAMP stack talking to arduino UNO or Leonardo on: July 05, 2013, 01:30:13 pm
Yes, those are all good points and should be part of the spec.  Thank you for catching my oversight!
10  Using Arduino / Project Guidance / Re: Raspberry Pi + LAMP stack talking to arduino UNO or Leonardo on: July 05, 2013, 12:03:29 pm
Well... thanks for bumping the thread.
11  Using Arduino / Project Guidance / Re: Raspberry Pi + LAMP stack talking to arduino UNO or Leonardo on: July 05, 2013, 10:19:30 am
Well not with THAT attitude.

I'm thinking some kind of daemon running on the pi that acts as a go-between, keeping the connection open and queueing messages in both directions.  I've never written a daemon in linux before so I'm not sure where to start.  Kill the daemon when appropriate to perform an upgrade, then restart to continue normal operations.
12  Using Arduino / Project Guidance / Raspberry Pi + LAMP stack talking to arduino UNO or Leonardo on: July 04, 2013, 04:10:43 pm
I want to build the next UI for my robot in a website so that I don't have to translate it for other devices - anything with a browser should work.  It will also mean that the pi can use a cron() to update itself and upload new sketches to the arduino.

I can upload sketches to the arduino UNO with inotool.  I can't with Leonardo because I get out_of_sync or programmer_not_responding.
I can open a serial connection.
I have a pi running a LAMP stack with a website.
When I click a button on the website I can send data to the arduino.
When I click a button on the website I want to see a log of messages sent back from the arduino.

Every time I open a serial connection the UNO resets.
Every time I try to open a serial connection the Leo gives an out_of_sync error.

How do I maintain a connection so that I the arduino doesn't reset every time AND still be able to upload sketches without hitting the reset button?

Thank you!
13  Using Arduino / Interfacing w/ Software on the Computer / how to create a persistent USB serial connection between raspberry pi & arduino? on: June 23, 2013, 09:32:26 pm
I have a raspberry pi connected via USB to an arduino.  I can build and upload from the pi using inotool. 
I want a mini server to connect to the arduino, maintain the connection, and pass strings back and forth.
I want to be able to send instructions to the arduino from php.  I'm guessing I need to pipe using exec()?
I want to be able to get messages back to PHP from the mini server.  At the speed I'm going the time delay is not a big deal.

I've found many tutorials about listening to serial in linux.  I haven't found any yet about sending.

Can you help me, please?
14  Topics / Device Hacking / Re: UNO as a HID compliant joystick? on: May 07, 2013, 01:22:53 pm
Total cost UNO + USB Host Shield > Leonardo.  Decision made.

15  Topics / Device Hacking / UNO as a HID compliant joystick? on: May 07, 2013, 12:14:19 pm

I want my UNO to show up as a HID compliant joystick.  I've already written the sketch to run on the microcontroller.  I don't have the bootloader right.  I've been told DFU can do it, but then people in arduino said "no, buy extra hardware to do the job right."  I'd really really like to do the job without buying extra hardware.  Please: Is there a way?

Thank you!
Pages: [1] 2 3 ... 5