Show Posts
|
|
Pages: [1] 2
|
|
1
|
International / Scandinavia / Re: Dansk arduino webshop-Eksistere interessen?
|
on: April 19, 2013, 07:53:02 am
|
|
Nu skal man jo aldrig sige aldrig. Men der er jo allerede en række danske forhandlere. I lighed med andre benytter jeg e-bay til mange af de dele jeg bruger og ellers dk.rs-online.com til komponenter. Et krav er at du kan konkurere på prisen. Mvh Allan
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: Sending negative numbers from i2c slave via TinyWire
|
on: April 16, 2013, 02:28:21 pm
|
TinyWire only can only send one byte per request as seen here. https://raw.github.com/Bohdan-Anderson/HeartRateMonitor-ATtiny-I2C/master/i2c_difference/i2c_difference.ino. But you are right about errors in my requestEvent. So I corrected the code and now it is working. Yippee  So here's a good example (full code) for other beginners like me. Slave code: #include "TinyWireS.h" // wrapper class for I2C slave routines #include "PinChangeInterrupt.h" #define I2C_SLAVE_ADDR 0x26 // i2c slave address (38)
int pin = 3; //LED indicating raising and falling edges in both encoder channels int chA = 4;//Encoder channel A int chB = 1;//Encoder channel B volatile int state = HIGH; volatile int a=0; volatile int b=0; volatile int t=0; boolean changed = true; boolean firstbyte = true; byte lowByte; byte highByte;
void setup() { pinMode(pin, OUTPUT); pinMode(chA, INPUT); pinMode(chB, INPUT); TinyWireS.begin(I2C_SLAVE_ADDR); // init I2C Slave mode TinyWireS.onRequest(requestEvent); attachPcInterrupt(chA, tickA, CHANGE); attachPcInterrupt(chB, tickB, CHANGE); }
void loop() { digitalWrite(pin, state); }
void requestEvent() { if(firstbyte == true){ // on the first byte we do the math lowByte = (byte) (t & 0xff); highByte = (byte) ((t >> 8) & 0xff); t=0; firstbyte = false; //so next time though we send the next byte TinyWireS.send(lowByte); } else { TinyWireS.send(highByte); firstbyte = true; } }
void tickA() { a=digitalRead(chA); if (a==b) { t=t+1; } else { t=t-1; } state = !state; }
void tickB() { b=digitalRead(chB); if (a!=b) { t=t+1; } else { t=t-1; } state = !state; }
And the code on the Master (Arduino): #include <Wire.h> #define I2C_SLAVE_ADDR 0x26 volatile boolean haveData = false; volatile int value =0;
void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output }
void loop() { byte hb; byte lb; Wire.requestFrom(I2C_SLAVE_ADDR,1); if (Wire.available()) { // hb=Wire.read(); lb=Wire.read(); } Wire.requestFrom(I2C_SLAVE_ADDR,1); if (Wire.available()) { hb=Wire.read(); } value = ((hb<<8)+lb); Serial.print(lb); Serial.print(", "); Serial.print(hb); Serial.print(", "); Serial.println (value); delay(1500); }
I wish I would have found an example like this two days ago. Now I hope other can use it in their projects. Thank you pylon for leading my attention in the right direction.
|
|
|
|
|
3
|
Using Arduino / Networking, Protocols, and Devices / Re: Sending negative numbers from i2c slave via TinyWire
|
on: April 16, 2013, 01:31:39 pm
|
Hi pylon The pull-ups are 4.7K. I think it has to do with converting between integer and bytes. I have rewriten the requestEvent again: void requestEvent() { byte lowByte = (byte) (t & 0xff); byte highByte = (byte) ((t >> 8) & 0xff); if(firstbyte == true){ // on the first byte we do the math t=0; firstbyte = false; //so next time though we send the next byte TinyWireS.send(lowByte); } else { TinyWireS.send(highByte); firstbyte = true; changed = false; } } Now the ATtiny85 continue to read the encoder and send data. Its only the lowByte that contains a value when recieved by the master. Master loop now contains: byte hb; byte lb; Wire.requestFrom(I2C_SLAVE_ADDR,1); if (Wire.available()) { lb=Wire.read(); } Wire.requestFrom(I2C_SLAVE_ADDR,1); if (Wire.available()) { hb=Wire.read(); }
hb alwways contain 0. Only lb has a value. When encoder readings on slave are negative they are near 256. I can find the right value by subtracting 256 from lb value if lb is higher than 126. So it's me not mastering converting from integer to bytes and back again. My problem is not yet solved but reduced to binary arithmetic that I don’t fully understand yet.
|
|
|
|
|
4
|
Using Arduino / Networking, Protocols, and Devices / Re: Sending negative numbers from i2c slave via TinyWire
|
on: April 16, 2013, 11:53:14 am
|
Ok I see. Thanks Borland. I changed the requestEvent code to this to send two individual bytes: void requestEvent() { byte lowByte = (byte) (t & 0xff); byte highByte = (byte) ((t >> 8) & 0xff); t=0; TinyWireS.send(lowByte); TinyWireS.send(highByte); }
The slave stops working after a few requests. The master code loop now contains: byte hb; byte lb; Wire.requestFrom(I2C_SLAVE_ADDR,2); if (Wire.available()) { lb=Wire.read(); hb=Wire.read(); }
Master receives values only a couple of times and the slave stop reading the encoder. It may well be that the solution is simple, but I can't figure it out. I hope one of you clever people can.
|
|
|
|
|
5
|
Using Arduino / Networking, Protocols, and Devices / Sending negative numbers from i2c slave via TinyWire - SOLVED!
|
on: April 15, 2013, 03:11:31 pm
|
Hi I finaly made my ATTiny85 talk with my Arduino Uno. Only strange thing is that small negative integers like 2 become something like 253 when received by the master. How do I send and receive a negative integer? My slave read a wheel encoder. My master request current count when needed. This is the code on the slave #include "TinyWireS.h" // wrapper class for I2C slave routines #include "PinChangeInterrupt.h" #define I2C_SLAVE_ADDR 0x26 // i2c slave address (38)
int pin = 3; int chA = 4;//pin 3 int chB = 1;//pin 2 volatile int state = HIGH; volatile int a=0; volatile int b=0; volatile int t=0;
void setup() { pinMode(pin, OUTPUT); pinMode(chA, INPUT); pinMode(chB, INPUT); TinyWireS.begin(I2C_SLAVE_ADDR); // init I2C Slave mode TinyWireS.onRequest(requestEvent); attachPcInterrupt(chA, tickA, CHANGE); attachPcInterrupt(chB, tickB, CHANGE); }
void loop() { digitalWrite(pin, state); }
void requestEvent() { TinyWireS.send(t); t=0; }
void tickA() { a=digitalRead(chA); if (a==b) { t=t+1; } else { t=t-1; } state = !state; }
void tickB() { b=digitalRead(chB); if (a!=b) { t=t+1; } else { t=t-1; } state = !state; } This is the code on the master #include <Wire.h> #define I2C_SLAVE_ADDR 0x26 volatile boolean haveData = false; volatile int value =0;
void setup() { Wire.begin(); // join i2c bus (address optional for master) Serial.begin(9600); // start serial for output }
void loop() { Wire.requestFrom(I2C_SLAVE_ADDR,2); if (Wire.available()) { value=Wire.read(); } Serial.println (value); delay(1500); }
|
|
|
|
|
6
|
Using Arduino / Audio / Re: MSGEQ7 Works on breadboard. Stops Arduino on PCB.
|
on: January 20, 2013, 09:44:36 am
|
|
Finally I found the error. I want to share my approach if others should come in the same situation. First I desoldered the resistor and some capasitors to see if that changed anything. No result at this path. Then I carefully bended leg 1 and 2 of MSGEQ7 so only these two legs – the power legs – was attached in the IC socket. Now the PCB worked. Then I added leg 3 and 4 and the PCB stopped working. This way I isolated the problem to leg 3. This is the analog output. Now I could begin to measure resistance (or continuity) from this leg to every possible point on the PCB. Bingo, the reset pin on the Arduino was connected. A little solder between the reset pin and the trace from MSGEQ7 and to the analog pin 0 had escaped my keen eye – or maybe not so keen eye.
That also explain why the program never really started. As soon as MSGEQ7 began to send a signal high enough the Arduino was reset. Maybe turning power on made MSGEQ7 put pin 3 high. I don’t have a scope to test. But now it does not matter anyway.
|
|
|
|
|
8
|
Using Arduino / Audio / MSGEQ7 Works on breadboard. Stops Arduino on PCB.
|
on: January 19, 2013, 06:52:25 am
|
|
My project include SD Card reader, TLC5940 with 555 as external clock and MSGEQ7 for analyzing frequencies in music streamed from SD Card. The frequency spectrum is use to turn LED on and off via TLC5940. Good news is that everything works on the breadboard. I used Fritzing to help me make an Arduino shield. I used IC sockets for all IC’s so I can test them one by one. If I don’t put my MSGEQ7 in its socket, the code is running and music is streamed. When I power up with MSGEQ7 in its socket I don’t receive anything in my serial monitoring as I normally do. If I measure voltage over pin 1 and 2 on MSGEQ7 it reads 5v as expected. I have spent hours measuring resistance (continuity) on the PCB to check the circuit. Another thing I observe is that the LED on the Arduino (pin 13) is on. That could indicate that the program never starts because the SD Card uses SPI and initialization make it an SCK pin. Now my question is, does the fact, that Arduino never start the program indicate what is wrong? Ps. please don’t answer “Yes, it indicates that the wiring is wrong”. I know that. I need directions to look at, not answers without substance.
|
|
|
|
|
13
|
Using Arduino / Storage / Re: Second time i read dir arduino halts
|
on: November 25, 2012, 04:00:42 am
|
I still got a problem. Another problem is that the File wrapper for SdFat uses malloc so this assignment causes a memory leak unless you close entry How do I close these, they have no close-method.
|
|
|
|
|
15
|
Using Arduino / Storage / Re: Second time i read dir arduino halts
|
on: November 25, 2012, 03:08:58 am
|
Thank you for the answers. I appreciate. But I would very much like to understand the answers to. My intentions in the code are: Declare an two dimensional array of stings to hold up 8 file names. String files [1][3]; Then fill this array by counting i from 0 to 3 and j from 0 to 1 in this loop: do { entry = root.openNextFile(); lcd.setCursor((j*10)+1, i); String ename=entry.name(); files[j][i]=ename; lcd.print(ename.substring(0,ename.indexOf("."))); i = i + 1; if ((i==4)&&(j==0)) {j=1; i=0;} } while ((entry)&&(i+j<5)); So yes j could be one and i could be three. That's the idea. It also seems that after the first completion of this loop, the array is filled as intended. The values are now selectable and I can move a cursor around. This code: if (files[j][i]=="") {i=0; j=0;} ... is checking if an item is empty and if so jump's to the first item. Really works as intended, but only first time I run the sub. So what is wrong. I declare the array inside the sub to make it local. In this way I hope the memory is cleared after getting out of scope. Is this my mistake? Some has mentions that there could be issues with String-objects. But I cant find anything explicit about this. Could such issues play a role here?
|
|
|
|
|