Pages: [1] 2   Go Down
Author Topic: Wire.h and pin 13  (Read 3607 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an LED hooked up to pin 13 using the following code:

void setup() {
 pinMode(13, OUTPUT);
}

void loop() {
 digitalWrite(13, HIGH);
}

As soon as I include the Wire header file in this code, instead of getting a steady output from my LED I get an intermittent blinking.

I'm not able to use Wire and i2c with a HMC6352 compass (which I've successfully interfaced with a PIC previously) so I'm trying to troubleshoot... and I get all the way back to the beginning with this problem with the status LED.

Has anybody successfully used Wire yet? Did you have the same problem with pin 13?

I'm using a USB Arduino with version 6 of the software. Thanks for any help! - Charlie
Logged

http://www.charlie-roberts.com/midiStroke
Free software for MIDI control in OS X.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A little more info...

If I add Serial.begin(9600) to my setup and then try to send Serial messages in my loop this doesn't work either with Wire.h included.

It basically seems like including Wire.h hangs everything

I'm running the Arduino software on OSX 10.8
Logged

http://www.charlie-roberts.com/midiStroke
Free software for MIDI control in OS X.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this is a bump.

Is anybody able to even include Wire.h without it screwing up your sketch? If I don't hear otherwise, I guess I'll go ahead and post in the Bugs forum...
Logged

http://www.charlie-roberts.com/midiStroke
Free software for MIDI control in OS X.

London
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

On windows, I can include Wire.h in my sketch without problems.

Platform: Board - Arduino NG.   IDE - Arduino 0006 on Windows XP.  
Circuit: Just the board, connected to PC via serial-over-USB.  I'm looking at the built-in LED on pin 13.  Ok, on re-reading your post, I've repeated all tests with an external LED and resistor on pin 13.

Steps to test:

Step 1. I start with your basic "switch LED on" sketch, but with the following line added.
#include <Wire.h>
It runs with a solid LED, no probs.

Step 2. I extend to also do some serial out and to blink the LED a bit.  Again no problems.  
Complete sketch:
#include <Wire.h>

void setup() {
 pinMode(13, OUTPUT);
 Serial.begin(9600);
}
 
void loop() {
 digitalWrite(13, HIGH);
 delay(2000);
 digitalWrite(13, LOW);
 Serial.println("so far, so good...");
 delay(2000);
}

More?
Sorry, I haven't used the wire library, nor do I have the means to test it more fully right now.  

Someone else?
« Last Edit: November 16, 2006, 03:44:25 pm by neillzero » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks,

I'll try it under Windows shortly, see if I can get results there, and then post back to the board.

Thanks again. - Charlie
Logged

http://www.charlie-roberts.com/midiStroke
Free software for MIDI control in OS X.

Cologne, DE
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I just also tried to use the wire library in my sketch (running osX 10.4.smiley-cool. I have the same problems. When I want to make an output via "Serial.println" nothing is printed into the serial monitor. It seems that Wire.h hangs everything.

here is my sketch:

#include <Wire.h>

void setup()
{
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  delay(100);
  Serial.println("hi");
}



maybe there is a solution for mac users,

cheers,

fux
Logged

Cologne, DE
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,

I read some more information about the i2c interface (http://www.sprut.de/electronic/pic/grund/i2c.htm  >>> in german only) and you have to put a resistor (1,8 k ohm) to each wire. Otherwise the programm will hang up. now I tried to make two arduino boards "talk" to each other. It still didn't work, but if I find a solution I will post it.

cheers,

fux
« Last Edit: November 20, 2006, 06:17:57 am by fux » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Haven't tried with the resistors yet, but I did just try compiling running XP as a virtual machine in OS X using Parallels.

Same results as just using OS X. I knew it would be too easy if that just worked.

FYI, if you want to use arduino in XP via Parallels, you need to disable the OS X FTDIUSBSerialDriver.kext found in System/Library/Extensions. A slight pain (because you have to renable it to use arduino later in OS X), but nothing horrific.

I have linux installed via parallels too... maybe I'll try that as well. Although fux's recommendation about the resistors sounds like a more likely solution... but it's less geeky and fun... and it also sounds like neillzero got it to work in xp without having any resistors hooked up. hmmm.
Logged

http://www.charlie-roberts.com/midiStroke
Free software for MIDI control in OS X.

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd be surprised if the operating system mattered.  In general, the same thing ends up on the Arduino board regardless of your OS.  Though you never know.

Maybe there are other differences between the setups that have worked and the ones that don't?  Esp. in terms of how things were wired and which programs were running on which boards?
Logged

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

> Haven't tried with the resistors yet

You should! The I2C bus won't work without them. Dedicated I2C hardware might already have them built in, but the Arduino definitely doesn't.

« Last Edit: November 21, 2006, 12:00:35 pm by brainfart » Logged

Cologne, DE
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When you connect the board with the two wires (analog 4+5) plus one resistor for each wire to the 5+ of your board, the problem you descriped should be fixed. on XP my sketch doesn't hang up even if I leave the resistors, but on a mac I just got it runnin with the resistors (that's really weird). I think that you have to do this just on your "master" board, so for example if you use a second board as a "slave" you just have to put the two wires in the analog inputs 4+5, but I am not really sure about that. the "master_writer" sketch now works on my board, but the "slave_receiver" sketch on a second board hangs up.

sketch:

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

#include <Wire.h>

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.receive(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.receive();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

it seems that the function "receiveEvent" causes problems, because when one byte is received it hangs up. has anyone an idea, what could be the problem?

thanks,

fux
« Last Edit: November 22, 2006, 07:36:56 am by fux » Logged

Monument, CO
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using Mac OSX and I don't get the problem when I include Wire.h.

I am using an Arduino Ministamp, though, so that might be a difference.

However, when I do a Wire.begin(), it hangs.

I have pull-ups on the I2c bus (I'm using 10K's...not sure what values to use with the Arduino Mini).  It hangs with or without pullups.

Also, I started reading the wire code and am concerned that it may not work at all with the Mini.  Has anyone got I2c working with the Mini?

I have a working LCD on my setup and use it for debug.  I'm trying to set up to talk to the Sparkfun real time clock device on I2C.

Code:
#include <stdio.h>
#include <LiquidCrystal.h>
#include <Wire.h>

LiquidCrystal lcd = LiquidCrystal();

int loopct = 0;

// based on SFE Pic code, the RT device address is 0xD0
#define RT_DEVICE_ADDRESS  0xD0

void setup( void )
{
  lcd.init();
  digitalWrite(13, HIGH);  // turn on debug LED  

  lcd.printIn("Wire.begin()");
        
  Wire.begin();
  
  lcd.clear();

  lcd.printIn("Wire init done");
}


In the case above, I see "Wire.begin()" but it never displays  "Wire init done".  It seems to hang in the Wire.begin().

So, I started looking through the wire and twi code.   One of the things that concerns me is this:

Code:
void twi_init(void)
{
  // initialize state
  twi_state = TWI_READY;

  #ifdef ATMEGA8
    // activate internal pull-ups for twi
    // as per note from atmega8 manual pg167
    sbi(PORTC, 4);
    sbi(PORTC, 5);
  #else
    // activate internal pull-ups for twi
    // as per note from atmega128 manual pg204
    sbi(PORTD, 0);
    sbi(PORTD, 1);
  #endif

From what I can tell the internal pull-ups on an Atmega168 (arduino mini) is on PORTB.  Given the comments in the code re: Atmega128 and this is the default if it's not an Atmega8, it makes me think the Wire interface has not yet been ported to work with the Mini.

I've put a scope on the Arduino mini ADC4 and ADC5 ports and never see any activity with Wire.begin().  These ports are not pinned out - I soldered a small female breakaway header to the ADC4 and ADC5 ports so I could access them.

Again, I have doubts that the Wire library and the Mini are currently compatible.  Has anyone else researched this or succeeded with the I2C/TWI interface on the Mini?

But back to the thread - I can include Wire.h without a hang, but it is potentially because I'm using a Mini and Wire is hosed for an Arduino Mini (I suspect.)
« Last Edit: November 21, 2006, 10:56:12 pm by landon » Logged

Cologne, DE
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

here is my setup how I connect two boards over the i2c interface. note that the resistors goes from the two wires to the 5+ pin of the board. in this setup the left board is the "master" and the right one the "slave".


« Last Edit: November 22, 2006, 07:15:27 am by fux » Logged

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

> I think that you have to do this just on your "master" board

It doesn't matter where exactly you place the resistors between +5V and the I2C "backbone", it just needs to be done somewhere on the I2C bus.
Logged

Amsterdam
Offline Offline
Full Member
***
Karma: 0
Posts: 137
he's looking at you, kiddy...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is it just me, or can you use a analog input also as a output? i did'nt know that. Or did you make a error and used analog pins in stead of digital pins?
Logged

--
"We're all in this together..."

Pages: [1] 2   Go Up
Jump to: