Show Posts
Pages: 1 ... 7 8 [9]
121  Using Arduino / Networking, Protocols, and Devices / Re: Uno as I2C slave on: October 31, 2011, 12:40:20 pm
No I hadn't, but that is too basic for what I want. I can already do all that (except switch the SDA and SCL pins from 4 and 5 to 5 and 4 smiley-lol).
122  Using Arduino / Networking, Protocols, and Devices / Re: Uno as I2C slave on: October 31, 2011, 09:31:35 am
Well, you sort of indirectly answered my question, so thanks!

I want to take it further than what it is. Here is the (now working) program that I am using now:
Code:
#include <Wire.h>

int val_0;
int val_1;
int val_2;
int val_3;
byte buf[8];

void setup()
{
  Wire.begin(2);                // address #2 (NXT address 0x04)
  Wire.onRequest(requestEvent); // register event
}

void loop()
{
  val_0 = analogRead(0);
  val_1 = analogRead(1);
  val_2 = analogRead(2);
  val_3 = analogRead(3);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  buf[0] = val_0;
  buf[1] = val_0 >> 8;
  buf[2] = val_1;
  buf[3] = val_1 >> 8;
  buf[4] = val_2;
  buf[5] = val_2 >> 8;
  buf[6] = val_3;
  buf[7] = val_3 >> 8;
 
  Wire.send(buf, 8);
}
Now I want to have a register structure for I2C. I want to be able to read any one (or more in sequence) of the bytes from the registers I want to (according to the NXT which is the master). Using the above as an example, I want to be able to read just "registers" 6 and 7 (ADC 3). If registers aren't really usable, what about being able to sense which register I am requesting, and the length, and then building the buffer accordingly? On the NXT side (with the above Arduino program), it doesn't matter what register I request, the Arduino just starts sending from the beginning.
123  Using Arduino / Networking, Protocols, and Devices / Uno as I2C slave on: October 30, 2011, 06:16:48 pm
I am interested in using an Uno as an I2C slave. I want to be able to read inputs, and set output through I2C. I have had some success before, but have always had problems with arrays of char. If a char element is 0, then none of the rest of the array elements seem to exist (they all seem to be 0). I have messed around a little trying to get things to work, but so far no go. One work-around I came up with is to (for example) split a 10-bit ADC reading in half, and using two bytes of 5 bits for the data. The other 3 bits of the bytes I set to 1's, just so that the element wouldn't ever equal 0.

I think the reason of this behavior is related to the Arduino seeing an element of a string with the value of 0 as being NULL (the end of the string).

In this case though, I am not using characters, and I want full freedom. I don't really care about signed vs. unsigned, as I can deal with that in code.

I only need help with the slave part (probably just array information). I am using an NXT as the master, and have I2C working just fine.
124  Using Arduino / Programming Questions / Re: Slow programming (compiling) on: August 13, 2011, 08:16:26 am
It appears to be very processor intensive. Right now it seems to be using about 10-25% of the CPU power, but when compiling, it takes 70-85%.

This computer has 2GB RAM, and only about half of that is being used according to the monitor.

I guess I will just need to wait until I have access to a different computer to program.
125  Using Arduino / Programming Questions / Re: Slow programming (compiling) on: August 12, 2011, 01:44:52 pm
I disabled file scan, and that seems to make a little difference (now it takes about 17 seconds to compile). Any other ideas?

Edit: Scratch that, it just took 50 seconds.
126  Using Arduino / Programming Questions / Re: Slow programming (compiling) on: August 12, 2011, 12:11:48 pm
I held shift so that it would show the files it was using (or whatever), and it was just as slow. It proceeds to the next file very slowly (compared to what I am used to seeing) for all the files.

I don't have anything related to BT with this computer.
127  Using Arduino / Programming Questions / Slow programming (compiling) on: August 12, 2011, 12:16:18 am
Is there any reason that it should take 20 to 30+ seconds to compile ("verify") the "AnalogReadSerial" example program with my laptop running Vista 32-bit? I have the board settings set to COM 6 and Mega 2560 (the board I have been using). Is there anything I can do to improve the time? The actual programming time isn't bad at all (once it compiles). Is there like a setting or something to speed it up? Are there any programs that the computer could be running, known to drastically slow down the compiling? I am used to compiling 1000+ line programs in a matter of a few seconds for the lego NXT.
Pages: 1 ... 7 8 [9]