arduino expansion question

Hi all, I have an arduino uno, I want to connect a few more devices than the board pins can take, is it possible to connect two device pins to the one pin slot on the board, or is that not possible and I need to purchase a mega board for more connections.

Thanks Ian

is it possible to connect two device pins to the one pin slot on the board

Not normally.

I need to purchase a mega board for more connections.

No simply use shift registers:- http://arduino.cc/en/Tutorial/ShiftOut http://www.arduino.cc/en/Tutorial/ShiftIn

Thanks for that mike. One last question are you familiar with compass readings onto lcd? I am having a problem displaying the compass direction. i.e north south east west, the lcd wont display any other direction than north

One last question are you familiar with compass readings onto lcd? I am having a problem displaying the compass direction. i.e north south east west, the lcd wont display any other direction than north

CAn you post your code ?

wrt pins you can also use I2C chips like the PCF8574 to get more I/O lines. There are also analog IN/OUT I2C chips. Only drawback they are a bit slower than direct IO.
Finally you have multiplexer IC’s that can change 5 lines in 16 lines (4 lines for addres, 1 for data).
this one - 16 Channel Multiplexer - COM-00299 - SparkFun Electronics -
or with PCB - SparkFun Analog/Digital MUX Breakout - CD74HC4067 - BOB-09056 - SparkFun Electronics -

sorry, I should have included the sketch:

include

include

include

// Store our compass as a variable. HMC5883L compass; // Record any errors that may occur in the compass. int error = 0; int HMC5883LAddress = 0x42; // This is calculated in the setup() function int slaveAddress; int ledPin = 13; boolean ledState = false; byte headingData[2]; int i, headingValue; LiquidCrystal lcd(12,11,5,4,3,2);

void setup() { // Shift the device's documented slave address (0x42) 1 bit right // This compensates for how the TWI library only wants the // 7 most significant bits (with the high bit padded with 0) slaveAddress = HMC5883LAddress >> 1; // This results in 0x21 as the address to pass to TWI Serial.begin(9600); Serial.println("Starting the I2C interface."); Serial.println("Constructing new HMC5883L"); compass = HMC5883L(); // Construct a new HMC5883 compass. Serial.println("Setting scale to +/- 1.3 Ga"); error = compass.SetScale(1.3); // Set the scale of the compass. if(error != 0) // If there is an error, print it out. Serial.println(compass.GetErrorText(error));

Serial.println("Setting measurement mode to continous."); error = compass.SetMeasurementMode(Measurement_Continuous); // Set the measurement mode to Continuous if(error != 0) // If there is an error, print it out. Serial.println(compass.GetErrorText(error)); pinMode(ledPin, OUTPUT); // Set the LED pin as output Wire.begin(); lcd.begin(16,2); } void loop() { // Retrive the raw values from the compass (not scaled). MagnetometerRaw raw = compass.ReadRawAxis(); // Retrived the scaled values from the compass (scaled to the configured scale). MagnetometerScaled scaled = compass.ReadScaledAxis();

// Values are accessed like so: int MilliGauss_OnThe_XAxis = scaled.XAxis;// (or YAxis, or ZAxis)

// Calculate heading when the magnetometer is level, then correct for signs of axis. float heading = atan2(scaled.YAxis, scaled.XAxis);

// Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location. // Find yours here: http://www.magnetic-declination.com/ // Mine is: 2? 37' W, which is 2.617 Degrees, or (which we need) 0.0456752665 radians, I will use 0.0457 // If you cannot find your Declination, comment out these two lines, your compass will be slightly off. float declinationAngle = 0.0457; heading += declinationAngle;

// Correct for when signs are reversed. if(heading < 0) heading += 2*PI;

// Check for wrap due to addition of declination. if(heading > 2*PI) heading -= 2*PI;

// Convert radians to degrees for readability. float headingDegrees = heading * 180/M_PI;

// Output the data via the serial port. Output(raw, scaled, heading, headingDegrees); // Flash the LED on pin 13 just to show that something is happening // Also serves as an indication that we're not "stuck" waiting for TWI data } // Output the data down the serial port. void Output(MagnetometerRaw raw, MagnetometerScaled scaled, float heading, float headingDegrees) { Serial.print("Raw:\t"); Serial.print(raw.XAxis); Serial.print(" "); Serial.print(raw.YAxis); Serial.print(" "); Serial.print(raw.ZAxis); Serial.print(" \tScaled:\t");

Serial.print(scaled.XAxis); Serial.print(" "); Serial.print(scaled.YAxis); Serial.print(" "); Serial.print(scaled.ZAxis);

Serial.print(" \tHeading:\t"); Serial.print(heading); Serial.print(" Radians \t"); Serial.print(headingDegrees); Serial.println(" Degrees \t");

if (ledState) { digitalWrite(ledPin,HIGH); } else { digitalWrite(ledPin,LOW); } // Send a "A" command to the HMC5883L // This requests the current heading data Wire.beginTransmission(slaveAddress); Wire.write("A"); // The "Get Data" command Wire.endTransmission(); delay(10); // The HMC6352 needs at least a 70us (microsecond) delay // after this command. Using 10ms just makes it safe // Read the 2 heading bytes, MSB first // The resulting 16bit word is the compass heading in 10th's of a degree // For example: a heading of 1345 would be 134.5 degrees Wire.requestFrom(slaveAddress, 2); // Request the 2 byte heading (MSB comes first) i = 0; while(Wire.available() && i < 2) { headingData = Wire.read(); * i++;* * }* _ headingValue = headingData[0]256 + headingData[1]; // Put the MSB and LSB together_ * int gradi = int(headingValue / 10); * int fraction = int(headingValue % 10);* * Serial.print("Current heading: ");* * Serial.print(gradi); lcd.print(gradi); // The whole number part of the heading* * Serial.print("."); lcd.write('.');* * Serial.print(fraction); lcd.print(fraction); // The fractional part of the heading* * Serial.print(" degrees Direction: "); lcd.print(" degrees");*

  • lcd.setCursor(0,1);*
  • if ((gradi >= 337 && gradi <= 359) || (gradi >= 0 && gradi < 22))*
  • { Serial.println("N"); lcd.print("North");}*
  • else if (gradi >= 292 && gradi <= 336)*
  • { Serial.println("NW"); lcd.print("North-West");}*
  • else if (gradi >= 252 && gradi <= 291)*
  • { Serial.println("W"); lcd.print("West");}*
  • else if (gradi >= 207 && gradi <= 251)*
  • { Serial.println("SW"); lcd.print("South-West");}*
  • else if (gradi >= 157 && gradi <= 206)*
  • { Serial.println("S"); lcd.print("South");}*
  • else if (gradi >= 112 && gradi <= 156)*
  • { Serial.println("SE"); lcd.print("South-East");}*
  • else if (gradi >= 67 && gradi <= 111)*
  • { Serial.println("E"); lcd.print("East");}*
  • else if (gradi >= 22 && gradi <= 66)*
  • { Serial.println("NE"); lcd.print("North-East");}*
  • else*
  • Serial.println("");*
  • lcd.print(scaled.YAxis);*
  • delay(1900);* }

please modify your post, select the code and press the # button (above the smileys) That makes it more readable.