Show Posts
|
|
Pages: 1 2 [3] 4
|
|
31
|
Forum 2005-2010 (read only) / Interfacing / Re: Microchip 24xxnnn i2c EEPROM
|
on: April 10, 2008, 06:10:19 pm
|
|
There's some undocumented funny business with the Wire library and I2C addresses. The Wire lib will take care of the I2C least significant address bit (the read or write bit) for you, so if you pass in the full 8-bits including read and write, this ends up getting shifted, and your address is invalid. This problem happened a lot to me when I was working with an I/O expander and an RTC. Suffice to say, the answer was nowhere on the Arduino or Wiring sites.
I have the 24C02C version of this chip, and its address is: 1010(A0)(A1)(A2)(W/R). If I had all my A pins tied to ground, the address I would pass the Wire calls would be: 101 0000, or 0x50.
|
|
|
|
|
32
|
Forum 2005-2010 (read only) / Interfacing / Re: Using interrupts and wire library?
|
on: April 17, 2008, 01:32:10 pm
|
|
Wire does use interrupts.
Best thing to do is to set a flag in your interrupt service routine, and then call that function from your main loop depending on the value of the flag. This way your ISR runs quick, and you have a better chance of not missing any other interrupts if you're using them.
|
|
|
|
|
33
|
Forum 2005-2010 (read only) / Interfacing / Re: Are LEDs and Resistors Washable? (LilyPad)
|
on: April 12, 2008, 12:09:41 pm
|
Why in the world would you want to hand wash electronic components? He says he's working with an Arduino LilyPad - the variety of board designed to be sewn into clothing. I'd imagine you'd need to wash the clothes eventually! One thing to note though: You will need to remove the batteries when you do wash. Otherwise, there's an excellent chance the battery's terminals will get shorted, and that's generally a bad thing. As it says on the Sparkfun page: "They're even washable - but be sure to remove the battery!" (:
|
|
|
|
|
34
|
Forum 2005-2010 (read only) / Interfacing / Re: Arduino Diecimila with Bluetooth
|
on: April 10, 2008, 06:44:47 pm
|
|
You don't need to write a new bootloader to make this module work with the Arduino... unless you wanted to be able to program the chip via bluetooth. I think you should be able to connect this chip's RX to Arduino's pin 1, TX to pin 0, and RTS and CTS to ground, unless you want to connect them up to other pins and use them, but you'd have to control them from within your sketch.
Because your chip seems to take 3v power, you might have to add some resistors to your setup... I can't say for sure though. : \
|
|
|
|
|
35
|
Forum 2005-2010 (read only) / Interfacing / Re: Overcurrent on IO pins
|
on: April 06, 2008, 01:56:27 am
|
|
I've run LEDs directly off the ATmega168. I'm running LEDs off it now. I'm running an LCD backlight off it too. I've only fried one thing - a green LED. But that was me being stupid so I deserved it. Wasn't even attached to the ATmega.
|
|
|
|
|
36
|
Forum 2005-2010 (read only) / Interfacing / Re: real time clock
|
on: April 02, 2008, 12:32:05 pm
|
|
They have different features, and they're from different manufacturers. The differences are probably not terribly important if you just want it to keep time, but it's still a good idea to check their features and figure out what you need or don't need.
As far as I know, they both use the I2C (Or Two-wire interface) that will use analog pins 4 and 5 on the Arduino. Until you know exactly which chip you're going to get, it's a little difficult to give you sample code, as I'd imagine the memory layout for each chip is different.
|
|
|
|
|
37
|
Forum 2005-2010 (read only) / Interfacing / Re: using more than 8 leds
|
on: April 02, 2008, 12:15:11 am
|
According to the datasheet, (pages 304+) each pin can source 40mA. As for maximum current for the whole chip, I can't tell. :| If you want to drive the LEDs from a constant power source rather than the Arduino but still control them, you can use some transistors and use the Arduino's I/O pins to switch the current flow through the LEDs on and off. You'd be looking at wiring them up as illustrated here: http://www.arduino.cc/playground/uploads/Learning/multiple_leds2.jpgOf course, you don't need to have 4 LEDs, or you can have more... It's up to you - and how much current the transistor you use is able to handle without bursting into flames.  To handle more than 16 LEDs, you're going to have to either purchase I/O expanders, like the Microchip MCP23008 (one I'm using) that will add more I/O lines to your Arduino, or do some tricky multiplexing as illustrated here: http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix Though it shows you how to use an LED matrix, you can wire up your LEDs in a similar way to achieve the same end. EDIT: Seems I missed a part of the datasheet... Seems the total output current for the analog pins (which can double as output pins), plus pins 0-4 should not exceed 150mA, and the total output current for pins 5 - 13 should not exceed 150mA. I'd try to stay below that as much as possible though, but that's just me, and I'm paranoid. ;p
|
|
|
|
|
38
|
Forum 2005-2010 (read only) / Interfacing / Re: Wire library on a device address > than
|
on: March 16, 2008, 05:45:07 pm
|
|
I'd assume it's some sort of buffer thing... Wire sticking the data you're writing out into the buffer, sends it along the wire, and then waits for a read. When it doesn't receive any data, it passes back whatever is in the buffer... which happens to be exactly what you wrote in. ... I could be wrong though, but this would sort of make sense as to why we get data out instead of a failure (which would be preferable in this case.)
Anyway. Good luck with your project! (:
|
|
|
|
|
39
|
Forum 2005-2010 (read only) / Interfacing / Re: Wire library on a device address > than
|
on: March 16, 2008, 12:35:12 pm
|
|
I2C addresses consist of only 7 bits. The last bit is Read/Write - Write when 0, read when 1. So, if you have a data sheet that says the address of a device is 0xA4, likely that's the Write address. The Wire library is poorly documented on this, but you have to pass the device address, which is the top 7 bits. So your A4 will become 0x52 and the Wire library will figure out whether you want the read or the write address.
So, to answer your question, the 7 bit address B1010010 will be made into B10100100 for writes to the device and B10100101 for reads from it, while the 8-bit address I couldn't say what would happen... probably that it will get made into an incorrect 9-bit address. Wire's functions expect the 7-bit device address - without the Read/Write bit.
I had a _lot_ of problems with I2C until I figured this out. I was trying to read input from an I/O expander, and the data that was getting read back to me was exactly what I had 'written' to the device moments before, but the voltage of the output pins reflected otherwise. So, although it may appear to be working properly, the device hasn't actually received any data. It really frustrated me, because this little 'quirk' is documented nowhere on the Arduino or Wiring site. I had to read about it on a blog somewhere on the internet.
|
|
|
|
|
41
|
Forum 2005-2010 (read only) / Interfacing / Re: External Power Supply Matrix
|
on: February 29, 2008, 12:54:46 pm
|
|
You'd only really need the transistor at one place in the circuit. Since current only flows when there is a complete path, one break is enough to prevent it moving.... The short answer is that it should work with only your NPN transistor before ground.
... Just make sure you connect your arduino pin to base, and connect both grounds. (:
|
|
|
|
|
42
|
Forum 2005-2010 (read only) / Interfacing / Re: SD-20 ic controler
|
on: March 07, 2008, 09:11:56 pm
|
The I2C bus is also called the TWI (Two-Wire Interface) in the ATmega168 data sheets. Lucky for you, the Arduino environment comes with a library that implements all the tricky stuff for you. It's the Wire library. You can probably do a search of the forum to pull up any other info you might need on it. (:
|
|
|
|
|
44
|
Forum 2005-2010 (read only) / Interfacing / Interrupt multiplexing with MCP23008
|
on: February 16, 2008, 07:33:02 pm
|
I'm having an issue with handling multiple interrupts. I have a Microchip I2C I/O expander connected to my Arduino board. The INT pin of the MCP is connected to pin 2 on the Arduino (Interrupt 0), and the I/O pins on the MCP are connected to switches and other junk that I want to capture interrupts from. This side works fine, they're all working properly. The Interrupts on the Arduino are enabled, and it works if I ground the line myself... the problem is that the MCP23008 should be doing this itself. I've gone through the data sheet several times, trying to figure it out, and I just can't seem to make it all work properly. Can anyone offer any advice/suggestions? Here is the code I'm using. The Lcd functions are in a separate file, work perfectly fine by themselves, and don't touch anything except LCD pins and such. : | /* Alarm clock "Proof of concept" */
#include <Wire.h> // I2C library from Wire. //#include <avr/pgmspace.h> // Program memory from Atmel #include <stdio.h> // printf and family
/*----------------------------------------------------------------- -- LCD communication pin definitions -- -----------------------------------------------------------------*/ const int int_pin = 2; // Pin Arduino is using Interrupts on const int lcd_rs = 3; // RS pin of LCD const int lcd_rw = 4; // R/W pin of LCD const int lcd_en = 5; // Enable pin of LCD const int lcd_db[] = {6, 7, 8, 9, 10, 11, 12, 13}; // LCD data pins const int lcd_db_size = 8; // # data pins in array
/*----------------------------------------------------------------- -- Strings and buffers -- -----------------------------------------------------------------*/ char string_buffer[17]; // 16 characters + null const char str_12hr_time[] = " %2x:%02x:%02x%cM "; const char str_24hr_time[] = " %02x:%02x:%02x "; const char str_date[] = " %3s, %3s %02x "; const char str_weekday[][4] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"}; const char str_months[][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/*----------------------------------------------------------------- -- Interrupt Shennanigans -- -----------------------------------------------------------------*/ volatile bool int_flag; // Place to hold interrupt flag byte int_mask; // Bit mask of each interrupt line that was toggled. const byte int_active = B00011111; // I/O expander lines with something that triggers interrupts
// Interrupt service function void Interrupt() { // All we need to do is indicate that an interrupt's been fired. int_flag = true; }
// Setup junk. void setup() { // Set up I2C first. Wire.begin(12); Serial.begin(9600); pinMode(2, INPUT); Serial.println("Yo!"); // Configure RTC for 1Hz Clockout Wire.beginTransmission(0x51); Wire.send(0x0D); Wire.send(0x83); Wire.endTransmission(); // Set up the I/O Expander to produce interrupts Wire.beginTransmission(0x20); Wire.send(0x00); Wire.send(0xFF); Wire.send(0x00); Wire.send(int_active); Wire.send(int_active); Wire.send(int_active); Wire.send(0x04); Wire.endTransmission(); // Fire up the LCD LcdInit(); //Wire.beginTransmission(0x20); //Wire.send(0x00); //Wire.endTransmission(); Wire.requestFrom(0x51, 11); while (Wire.available()) { Serial.println(Wire.receive(), BIN); } // Start interrupts to falling edge attachInterrupt(0, Interrupt, FALLING); }
// The main guts. void loop() { // Check if an interrupt has fired. if (int_flag) { // Clear the interrput flag now - if our routine takes too long, we might (will) miss // the next interrupt, which WILL fuck things up. int_flag = false; // Get data from the I/O expander to see which buggers fired. Wire.beginTransmission(0x20); Wire.send(0x07); Wire.endTransmission(); Wire.requestFrom(0x20, 2); Serial.println(int_mask = Wire.receive(), BIN); Serial.println(Wire.receive(), BIN); // Do ... something. if (int_mask & 0x01) { byte sec, mins, hrs, day, wkd, mth; // CLKOUT fired. Update LCD. Wire.beginTransmission(0x51); Wire.send(0x02); Wire.endTransmission(); Wire.requestFrom(0x51, 6); sec = Wire.receive() & B01111111; mins = Wire.receive() & B01111111; hrs = Wire.receive() & B00111111; day = Wire.receive() & B00111111; wkd = Wire.receive() & B00000111; mth = Wire.receive() & B00011111; // Write new time LcdSetPos(0,0); sprintf(string_buffer, str_24hr_time, hrs, mins, sec); Serial.println(string_buffer); LcdPrint(string_buffer); sprintf(string_buffer, str_date, str_weekday[wkd], str_months[mth - 1], day); Serial.println(string_buffer); LcdSetPos(1, 0); LcdPrint(string_buffer); } } }
|
|
|
|
|
45
|
Forum 2005-2010 (read only) / News / Re: Arduino 0011 released.
|
on: April 01, 2008, 01:13:54 pm
|
The macro is need any where you would have previously used as a cast. It allows people to avoid learning the cast syntax. I think I can see where you're coming from, trying to make things easier for newbies, but I think the casting syntax isn't that complicated that it should need a macro. Are there any intro-level tutorials for writing C/C++ on the Arduino on the site anywhere? Perhaps if there were some basic C tutorials available, macros like this wouldn't be needed, as the tutorials should cover basics like casting.
|
|
|
|
|