text:
motor affecting time calculation between hardware interrupts
My robot uses an Arduino Mega 2560. It has 6 IR receiver modules connected to its 6 external pins namely 2, 3, 18, 19, 20, and 21.I have connected the Pololu MC33926 dual motor driver arduino shield to my arduino(here is the connections diagram : https://www.pololu.com/docs/0J55/3.c ). I generate a 56KHz IR signal with an LED from another Arduino. The IR receiver modules convert the 56KHz signal into a active low digital signal. My signal consists of a signature bit followed by 32 bits of data. a binary 1 is represented by a signal of length 1200 uS and a binary 0 is represented by a 600uS signal with intervals of 600uS. I employed a state machine in my code which checks the duration of time between falling edge and rising edge. and vice versa and compares it to the duration expected. If anything is not expected it discards as noise and goes back to the idle state. If the duration is as expected it goes to the next state and then takes in the entire 32 bits and converts this binary format into a decimal value. I print this value on a 7 segment display on my robot. It works perfectly when the motor's are not running.
      Now this is the case when the motors are running. It does not receive the signal. I have tested every component individually and these are the results:

The receivers still receive the signal perfectly, and their output to the Arduino is also as expected. No problem there.
Earlier the Arduino was being powered through the Motor driver. Just to make sure that was not the problem I separated the Arduino's power supply from that of the motor driver. Still the same issue, i.e. the robot does not receive a valid signal(at this point i realized the arduino receives a valid signal but isnt able to decode it accurately).
We then printed out the values of time differences between each rising and falling edge on the interrupt pins. These values seem correct and within the tolerance range when the motors are switched off. But when the motors are switched on these values are not right. Of the 32 duration's measured, atleast two are not right(for eg. instead of 300 uS it calculated 88uS) due to which the signal is being discarded as invalid.
I thought that the PWM being generated to control the speed of the motors on digital pin 9 and digital pin 10(OC2B AND OC2A). Even though the PWM signals were being generated(without the motors connected) the signal was still being read as valid and the robot was receiving the signal. So its not that either.

The only anomaly I have found are the readings of the durations of the interrupt intervals. Can somebody please tell me what connection I have done wrong. Its mostly not with the program since it works otherwise. Something with the motor is making the Arduino act weirdly. Any help will be greatly appreciated. I have to scale up these robots to build a swarm and I am still stuck in the first step.
Thanks a lot.

Noise from electromagnetic sources is always an important issue that must be addressed. The aims are to minimise noise generation at source, reduce transmission of noise between source and the "target" affected circuitry and reduce noise impact at the target.
Motor controller circuit diagram here
The shield power supply link MUST have been removed.
Shield must have all own powering.
Coupling via a common eg 5V supply has a high chance of being problematic.
The two 5V supplies (arduino & shield) could have a common higher voltage source but need separate regulators and proper noise removal in each supply.
Placing extra capacitance across the arduino Vin or main power source MAY help.
I assume that the motors are driven in either direction during operation. If not then a reverse diode across the motors should help.
If bidirectional,  try reversed diodes from each motor lead to Vout (= V+ motor drive voltage).
The shield's Vout filter capacitors C7 & C8 care 47 uF each.
Vout could usefully have 1000 or so uF added somewhere on the board.
I do not know how much motor current is drawn and exact control strategy. This MAY interfere with motor drive but probably not: Identify one motor which "has issues". Add a small series resistance in each lead with a capacitor across the leads on the motor side. Here "small" means "does not noticeably affect performance". eg 1 Ohm if Imotor < to << 1 amp. Capacitor needs to be biplar for bidirectional motor control - eg a 1 uF ceramic or plastic (polyester, mylar, ...) cap.
'If all else fails'[tm] opto coupling the driver interface is possible BUT should not be needed.
Try above.
Report.
Ask more questions if needed.

Thanks for the above answer. It got me thinking on the right track. After some reading through the motor driver data sheet I realized that I forgot totally about the by-pass capacitors. After connecting a 0.1uF cap between two terminals of the motors and another two between the terminals and the casing the results are much better. It can receive a valid signal from another robot(though not as well as when the motors are turned off). Any suggestions where else I could place by pass cap's to further eliminate electrical noise?
Again,
Thanks a lot guys.
really appreciate the help.

In the other places I mentioned.


text:
Wiring Lilypad USB + ESP8266 Serial WiFi Module
I am trying to solve the following scenario:
Lilypad USB connected to WIFI through ESP8266 Serial WiFi Module.
http://arduino.cc/en/pmwiki.php?n=Main/ArduinoBoardLilyPadUSB
http://www.seeedstudio.com/wiki/WiFi_Serial_Transceiver_Module
According to the wiki:
I should connect to TX RX pins. None of them are present as "selectable pins", because they are built in.
This post Using LilyPad Arduino USB with LilyPad Xbee Shield  talks about using SoftwareSerial something that is new to me.
Could anyone explain how should I proceed with the wiring and if possible a sample sketch just to connect the lilypad usb with the WIFI module to my personal WIFI.
Edit:
I found the following tutorial (spanish one but easy to follow...) where they use the Arduino UNO. I tried the example with the software serial and it worked.
I saw in that tutorial sometimes the pin RST is needed. So I tried to do the same with the lilypad USB, but still didn't work.

First, upload the sketch below to your Arduino. Then, try to tie RX (pin 3) and TX (pin 2) of SoftwareSerial together. Open the Serial Monitor and send some text and see if you get it back as a response.
#include <SoftwareSerial.h>
SoftwareSerial Serial1(3, 2);

void setup()
  {  Serial.begin(9600);
     Serial1.begin(9600);
  }

void loop()
  {
     if (Serial1.available())
         { char c = Serial1.read() ;
           Serial.print(c);
         }
     if (Serial.available())
         {  char c = Serial.read();
            Serial1.print(c);
         }
   }

Once you get a response, then your SoftwareSerial part is working and you can then try to connect to your ESP8266.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

authors: Nabil Akroud - نبيـــل عكــرود

sort: votes


text:
Error while saving data in text file
I created a function that saves the timestamp in a text file, but it saves unreadable. Full of invalid characters, example: Ÿ@Â   O   ƒº!¥ Ÿ@Â   O   ƒº!¥ Ÿ@Â   O   ƒº!¥ Ÿ
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include "RTClib.h"

RTC_Millis rtc;
File txt;
const char * getCurrentTimestamp()
{
    char dateBuffer[40];
    DateTime now = rtc.now();
    sprintf(dateBuffer,"%02u-%02u-%04u %02u:%02u:%02u", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
    return dateBuffer;
}

void saveLog()
{
  txt = SD.open("dados.txt", FILE_WRITE);
  txt.print(getCurrentTimestamp());
  txt.close();
}

void setup() {
  pinMode(53, OUTPUT);
  SD.begin(4);
  Serial.begin(9600);
  rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
}

void loop() {
  Serial.println(getCurrentTimestamp());
  saveLog();
  delay(1000);
}

My code is very simple, do not understand where I went wrong. if I copy the following code snippet for saveData() function and save the dateBuffer variable, everything works normally.
char dateBuffer[40];
DateTime now = rtc.now();
sprintf(dateBuffer,"%02u-%02u-%04u %02u:%02u:%02u", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());

how to save the timestamp correctly in the file through the function getCurrentTimestamp() ?

Your function, getCurrentTimestamp() saves the date string in an automatic variable - it is on the function's stack frame which gets freed as soon as that function returns. Either Serial.println() or savelog() is overwriting it.
The proper way to do what you're trying to do is to make the buffer live for the duration of both function calls. One way is to use a global buffer. Another is to declare the buffer in loop() and pass it to both functions.

As far as I know you should use
text.write(getCurrentTime());

That because (if I'm not wrong) you need to send it as ASCII characters so the text editor will be able to read them in the right way.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
How can I run two Arduinos in sync for video generation?
I was thinking about building a video circuit that uses two Arduinos (maybe more) to generate video using NTSC and the AD725.  Although, VGA might be nice if possible.
Anyway, the idea is to use one Arduino as the background layer and the other one as the sprite layer (overlay).
Then, instead of masking the sprite data and having more cpu time, I was thinking of running the signals through a mux.  So that when drawing background data and no sprites (per scanline) then pipe the signal to the AD725.  But when there is a sprite mid-line, then the >0v signal of the sprite Arduino would cause the mux to pipe its contents through to the AD725.
Or, something similar.
I believe many arcade boards from the 80's did this.  Many of them had entire "sprite boards" attached and the signals would mix.  Each layer would have it's own RAM and not be aware of the other layer.
But to do this, I would have to keep the Arduinos sync'd perfectly.
So that's my question.  How I can do this?
Oh, my Arduino of choice in the beginning would be the UNO but I have others (DUE, Teensy3.1, etc.) if that would be a better fit.
Thanks.

I would discourage using arduino for anything with video.
A raspberry Pi comes with a built-on HDMI-out aswell as GPIO pins.

Not really interested in using the RPi for this.  But thanks anyway.

Arduinos are great for many things, and I think the idea of synchronizing two or more Arduinos might have several applications.
However, if I wanted to generated VGA or NTSC video, I would look at the Parallax Propeller as another option.
Many people use the Parallax Propeller to produce VGA video, keeping its 8 processors working in parallel.

"Hive retro computer"
"containing a total of 24 RISC processors, VGA graphics, stereo sound, ...
uses all DIP and through hole components."
"Signal processing module using Parallax's propeller chip",
apparently can do "video in ... to do video-overlay then send it to video out."
Dangerous prototypes has a long list of projects using the Parallax Propeller.
"Dangerous Prototypes: Parallax Propeller"
"Pocket Mini Computer on Parallax Propeller" includes VGA output
"Propellerpowered Forums" includes many people discussing video output on the Parallax Propeller.
etc.

I decided on the Propeller.  It's almost like it was made for this task.  :-)

I would take a look at MREtv which seems to promise all that you want to do, with just one arduino. This might not be the answer you're looking for, but getting threads to sync is a pain in the rear end, see this for explanation of why threads are a pain.
Now back on topic, it seems like MRETV might off what you want to do, and it can do some pretty impressive things from what I read in the arduino. You might need to modify the library a bit, but it offers already implemented encoding, so that is a plus.
http://www.instructables.com/id/MRETV-Video-Stereo-Sound-and-much-more-from-a-s/

I tried to get that MRETV to work.  Followed the instructions to the letter and it wouldn't even compile.  This is on a fresh install of the Arduino IDE (newest version).

@cbmeeks Could you give me details of what the IDE spat out when it failed to compile? Are you on windows? What was the actual error, the ide couldn't find a file?

I don't have the exact error in front of me at the moment.  But I'm on a Mac and the error was something along the lines of "must define const sound" or something like that.

You would need to use interrupts on the "sprite arduinos" to get the timing very exact - the "background" arduino would need to send signals sync signals (horizontal and vertical) to the sprite arduinos. The sprite arduinos would then need to keep track of which line it is on, and time exactly how far along the line it is. You will need a circuit to either allow the incoming signal through (I believe the arduino will be too slow to pass it read it, then write it);
alternatively, have multiple (still synchronized) sources, each indicating if they want to be on the screen; then one that takes the "I want to be on the screen" signals, make a decision, and connect the appropriate one (via a transistor).
A basic tutorial on TV out is found at:
http://playground.arduino.cc/Main/TVout

Just a thought, you could try synchronizing micros() / millis() between Arduinos... [ https://aaka.sh/patel/2013/12/23/synchronizing-micros-millis-arduino/ ]
Over time you could set instructions/commands to execute at certain time intervals on target arduinos using something as simple as a 2 wire serial setup  [ http://arduino.cc/en/Tutorial/MasterReader ]


text:
Connect the output of an Arduino to the input from another Arduino
I'm making a project and i'm trying to send bits from an Arduino to another Arduino with the digital pins. So my setup are 2 Arduino's connected with a jumper.
I connected the grounds and they have both a different power supply.
Now I tried this set-up and as soon as I connect the output pin to the input pin from the other Arduino the voltage lowers from 5V to 2.6V so we can't detect our bits.
Anybody an idea how to solve this problem?
Thanks in advance!
Kind regards,
Manu

Schematic and code?

Do they both have the same voltage supply?

Well, it could be the bad case of two NOT floating PSs with different ground levels.

Or a simple case of two outputs connected together, driving different levels.

How did you measure the 2.6v you're talking about? (Also, you probably should add a resistor in between, just in case the voltages between the 2 arduino's are not exactly the same).

We measured it with an oscilloscoop. The strange this is we tried everything that is commented below. We will try an optocoupler, maybe this will work. We are pretty sure it ahs nothing to do with the code because we stripped everything to the basics because we thought the code wasn't working. We wrote a new code just to detect if the input was 1 or not and even that is not working. We are thinking it has something to do witch the reference voltage (ground).

Schematic will help. Also, tell us if the 2.5V is on the data line connecting the two arduinos, or did the power of any of the arduinos dropped to 2.5V?

As you are trying to communicate with two arduinos I will suggest you to use some sort of standard communication protocol such as Two wire interface or I2c. There is the Wire.h library you can use and it has also a reference on the main Arduino site. If you have different necessity and want to carry on with you're methods you need to specify in more depth the connections you have made. As for now I can guess that the output is being connected to ground or some sort of load and that might be the reason you are seeing a drop out of voltage. But it might be also the case that you're output pin is changing so fast that the multimeter is not capable of reading the high state correctly

As Harry mentioned better to use some communication lines like UART or I2C or SPI.
If you dont have them available then use digital i/os but make sure their pull up and pull down resistors are correctly configured. If it is input just set as pull up and for output set as output pin.
Regards,
Pathik

Please do not repeat what others have already said as it leads to clutter on the site.

I would suggest sticking a transistor in between - use a layout like http://en.wikipedia.org/wiki/Transistor#/media/File:Transistor_Simple_Circuit_Diagram_with_NPN_Labels.svg (from the wiki page on transistor).
Note that Vout should be connected to the input pin on one arduino, and Vin should connect, via a resistor, to the output pin on the other arduino.
Just to confirm, the labels are reversed from what you will expect them to be.
The 2 resistors can be anything > 1kOhm.
This still depends on the common ground.
Note that common ground may not be a good idea if they are generated from the same power source - I've found ground from two USB ports on the same laptop to be at different levels, so current will flow out from one port, and in the other, probably damaging the laptop, if the two grounds are connected.

First of all, I cannot say if your protocol will work or not since I don't have the details. However, switching protocols will give you the same result. Also, you do not need a transistor for this usage.
The solution is to connect the grounds of the different power sources. Since voltage is relative, having the grounds disconnected will lead one device to think that the voltage is higher/lower than the other one thinks (they have different reference point).

Are you sure one pins is configured as input? If one would be output high and the other output low you basically get a short circuit: from Vcc through the top FET of the high output, through the wire to the other Arduino, and into the lower FET of the low output, and back to ground.
If the short circuit were perfect the voltage would drop to zero, but both FETs have a non-zero resistance, which makes them a voltage divider.
One way to protect your Arduino against this (such a short circuit does damage the I/O circuits!) is to place a 1 kΩ series resistor between the pins. Since an input pin won't draw any current there won't be a voltage drop across the resistor either.
I wouldn't use Harry's I2C, because it's probably too complicated for your needs. (I don't know what data you want to exchange). A simple connection is the UART: one transmit line and one receive line. It's true that the UART is used for the USB communication, but that connection goes via a set of resistors, so that another controller using the bus should be able to override the USB's signals.
If you have a long distance between the Arduino's you'll want RS232 level shifters.


text:
Possibilities and limitations for onboard data acquisition
I could define myself as a "nerdy cyclist", so while my interest in Arduino is steadily growing (have not bought or used yet), my first idea for a project would be:

Instrument a bicycle with some sensors (accelerometer, reed switch, etc) and an Arduino;
Ride long distances (that is, four hours or more, sometimes non-stop);
When at home, download some sort of "data file" (from SD card, I think);
Analyze results with Python/Matlab/whatever.

So my questions:

Is any model of Arduino suitable for this purpose?
What is the expected sample rate vs number of channels? 100Hz per channel would be excellent for my purposes, for example.
Can I keep incrementally saving to SD "forever" (that is, while battery and card space are available)?

First of all your idea project is feasible. And to answer to your questions:

There is no right Arduino for your project simply because theoretically every Arduino board can do the job. But as you said it has to be portable you might use Arduino nano/mini or even Uno if you have enough room or space.
The acquisition rate depends on the on the type of sensor you have. So if you have let's say one analog reading you can use the built in function in Arduino which is capable of making about 10000 readings at time. So if you have multiple outs you can easily for the calculation. There are also sensors which has a digital output in this case in order to read your value you communicate with Tue sensor board through Two wire interface or I2C communication interface, for this there is a library you can use. Usually the speed at which this communication work s very high, at 100kHz( if I'm not wrong).
3.Yes you can save data on the SD card until you don't exceed the memory or the battery doesn't die.

I have a suggestion for your project, as you're going to acquire some sort of data and then analyze it on your computer, do less calculations on your Arduino board and let the PC handle the hard work.
Useful links:

Reference to the two wire communication: http://arduino.cc/en/reference/wire
Reference to the SD card reading on Arduino: http://arduino.cc/en/Reference/SD

I would venture to say that any Arduino can be portable for an arbitrary definition of "portable".

You're right but I was thinking about the space that the board itself occupies. Obviously any Arduino board can be used to do the job as I wrote.

In a long distance bike, I think the Uno is still considered portable. Putting it ahead of the headtube (possibly even inside a basket) would be acceptable I think (at least experimentally).

I would accept the answer, but you could please post links to what you are talking about. For example, "there is a library for that" doesn't teach me much, you could make it a link to the library itself.

Another idea -
I believe if you are making electronics you must be using some smart phone?
If I am correct why don't u utilize your smart phone with Arduino?
1) Connect sensors to Arduino
2) Use Bluetooth or WiFi shield
3) Store data locally until memory available
4) Transfer to your phone or to web via phone network every hour or 5 hours.
This will make battery consumption less and also make device Compaq.
Regards,
Pathik SHAH


text:
Trying to understand bitbanging, shiftIn(), reading EEPROM
Alright, so I have an Atmel 93C66, http://www.atmel.com/Images/doc0172Z.pdf Datasheet and I'm wanting to read whatever is in it.
I copied the following code from this thread http://forum.arduino.cc/index.php?topic=96411.0 and made some changes to it, mainly I deleted the part where it writes:
//difining pins for eeprom
int CLOCK =4;
int DATA_OUT =3;
int DATA_IN = 2;
int CHIP_SEL =5;

int low =0;     //low address

byte READ  = 0b1100;                //read instruction

void setup(){

  pinMode(CLOCK ,OUTPUT);
  pinMode(DATA_OUT ,OUTPUT);
  pinMode(DATA_IN ,INPUT);
  pinMode(CHIP_SEL ,OUTPUT);
  digitalWrite(CHIP_SEL ,LOW);
  digitalWrite(CLOCK, LOW);
  Serial.begin(9600);
}

void loop()
{

  for (int i=0;i<=511;i++)
  {
    digitalWrite(CHIP_SEL ,HIGH);
    shiftOut(DATA_OUT,CLOCK,MSBFIRST,READ); //sending READ instruction
    shiftOut(DATA_OUT,CLOCK,MSBFIRST,low);   //sending low address
    byte incoming = shiftIn(DATA_IN,CLOCK,MSBFIRST); //receiving data
    digitalWrite(CHIP_SEL ,LOW);

    Serial.print(low);
    Serial.print("/t");
    Serial.print(incoming, BIN);
    Serial.print("/t");
    Serial.print(incoming, HEX);
    Serial.println():

    low++;       //incrementing low address

  }
  while(1);
}

What I'm trying to understand is:
In the 93C66 datasheet page 5, table 6, it says that to read the contents of memory I need to send SB 1, OPCODE 10, and memory address, which I don't know exactly how to do, but I guess the chip wants a 110 (or a HIGH, HIGH, LOW signal) plus memory address (variable “low”=0). The SB and OP CODE are similar to the BYTE variable READ in the code above, but this variable has an extra 0 (1100). I tested the code with 110 and I get different incoming data. I also thought if BYTE is 8 bits then why not make the BYTE variable READ 11000000, but it changes the incoming data. So now I don't really know how exactly to send SB 1 and OP CODE 10. Need help with that.
Also, as you can see I'm printing the variable "low" and the variable "incoming" (in Binary and Hex) on one line, I thought it would be printing 1 bit per line, but it prints varying amounts of bits. Sometimes it would print 4 bits, 6 bits, or 8 bits, as in 1110, 11111111, 111100. I thought the line byte incoming = shiftIn(DATA_IN,CLOCK,MSBFIRST);
would get filled with 8 bits all the time, so when I Serial.print() it would have 8 bits, but it's not happening, why?
Also I thought the shifting in of the bits into the variable "incoming" occurs once in the for loop, or is there an inner loop in shiftIn()? I ask because I first made the for loop go for i=<4095, since there are 4096 bits in this EEPROM, but the increment of I doesn’t match the amount of bits I’m getting on each Serial.print() line.
i.e. I would get something like this:
1   10111111    BF

I thought it would be getting something like this. (I’m thinking the shiftIn() of the 1st bit at address 0 happens when i=0, then 2nd bits gets shiftIn() when i=1, and so forth)
1   1
2   1
3   0
4   1
Etc, etc

How is shiftIn() shiftinf in the bits into the BYTE variable?
Thanks and sorry if it’s so many questions.

OK I know this is a little late, but for other readers having the same problem, here's a sketch I wrote to read a 93c46 when I had to dump the EEPROM from a car radio. I've deliberately not included the EWEN instruction anywhere as the last thing I wanted to do was accidentally write to the EEPROM.
The key is the modified shiftOut routine which adds a parameter specifying how many bits you want to shift out.
To adapt sketch for other 93c packages, change the number of 16bit words at start of loop{} and number of address bits in 2nd call to myshiftOut.
If your package has an ORG pin, tie it to Vcc.
Hope this helps someone...
/*
Arduino Uno sketch to dump a 93c46 EEPROM in 16 bit mode.  Metalbanana 12/9/16, with thanks to raint.
Easily modified for other 93c series parts. Note many 93c46 from autos are 'rotated' pinout,
i.e. those with a T following part no. e.g. 'TEM8':

1=NC    8=ORG
2=Vcc   7=GND
3=CS    6=DO
4=SK    5=DI

so check pcb for Vcc and GND locations with a meter first! An Arduino ProtoShield is ideal to mount IC
as it has a SOIC pad (Note: you can't use the mini breadboard at same time as it covers one set of headers).
Standard shiftOut is not suitable as it sends 8 bits, our addresses are 6 bits,
instructions are 3 bits so sketch uses a modified shiftOut called myshiftOut.
*/

// define pins for eeprom
const int CHIP_SEL = 8;  // to CS
const int CLOCK = 9;     // to SK
const int DATA_IN = 10;  // to DO
const int DATA_OUT = 11; // to DI

const byte READ  = B110;                //read instruction

bool debug = 0;

void myshiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val, uint8_t bits)
{
  for (int i = 0; i < bits; i++)  {
    if (bitOrder == LSBFIRST) {
      digitalWrite(dataPin, !!(val & (1 << i)));
      if (debug)Serial.print(!!(val & (1 << i)));
    }
    else
    {
      digitalWrite(dataPin, !!(val & (1 << (bits - 1 - i))));
      if (debug)Serial.print(!!(val & (1 << (bits - 1 - i))));
    }
    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
  }
}

void setup() {
  pinMode(CHIP_SEL, OUTPUT);
  pinMode(CLOCK, OUTPUT);
  pinMode(DATA_OUT, OUTPUT);
  pinMode(DATA_IN, INPUT_PULLUP);

  Serial.begin(9600);
  Serial.println("\n\n");
}

void loop()
{
  for (int addr = 0; addr < 64; addr++) // 64 words for 93c46
  {
    // print address at start of each line
    if (addr % 8 == 0) {
      Serial.println();
      if (addr < 8) Serial.print("0");
      Serial.print(addr * 2, HEX);
      Serial.print(": ");
    }

    digitalWrite(CHIP_SEL, HIGH);
    myshiftOut(DATA_OUT, CLOCK, MSBFIRST, READ, 3); //send READ instruction
    myshiftOut(DATA_OUT, CLOCK, MSBFIRST, addr, 6); //send address, 6 bits for 93c46

    digitalWrite(CLOCK, LOW); // recommended in language reference
    byte incomingH = shiftIn(DATA_IN, CLOCK, MSBFIRST); //receive high byte
    byte incomingL = shiftIn(DATA_IN, CLOCK, MSBFIRST); //receive low byte

    // reverse byte order & print
    if (incomingL < 16) Serial.print("0");
    Serial.print(incomingL, HEX);
    Serial.print(" ");
    if (incomingH < 16) Serial.print("0");
    Serial.print(incomingH, HEX);
    Serial.print(" ");

    digitalWrite(CHIP_SEL, LOW);
  }

  while (1);
}


text:
Reprogram Arduino Mega 2560 using Duemilanove?
Experiencing that Mega 2560 uploading problem. Tried updating the IDE, worked for a while but symptoms went back. Now i want to reprogram that chip.
I'm asking this question cuz hardware ain't free and shipping is not instant.
I don't have a programmer. So we already know that we can program an arduino board with another arduino board as a programmer. However i just have a Duemilanove available. Will this work? Please do not answer if you're not sure.

Yes it is possible.
You can follow this tutorial: http://www.gammon.com.au/forum/?id=11635
The uno is basically the same as the Duemilanove


text:
My Computer Doesn't Realize ESP8266 ESP-05 is Connected or not
I wired ESP-05 to my usb-to-ttl as images below.
I connected it to USB #2 port, and my computer seems not knowing this.

I also tried to send "AT+RST" through Realterm but, it didn't work neither.

Can you try to describe what is happening and what the expected outcome of the action should be, maybe what you have tried. From what i can see everything looks fine, the RX/TX connection is where most people do wrong, but it looks like it is connected properly.

your problem is not with the ESP, but with the usb-ttl converter. You need to install manually the PL2303 driver.


text:
Use Arduino Uno to program the on-board Atmega328 in C
I have an Arduino Uno board.  I have seen how it is possible to program external AVR's through the Arduino Uno board, for instance an ATtiny. But I'm starting with c for atmel µc and I just want to program Atmel328's through the Arduino hardware, and being able to use the arduino pins for outputs etc.
So my question is, can I use the Arduino Uno board together with avrdude and avr-gcc to program the on-board atmel328 in C? And thus being able to use the Arduino pins for output and input?

You're question is not so clear.
But from what I understood you are asking if you can program the Atmega328 with c using low level instruction and by setting manually all the registers in order to use IO ports of atmega. If that's what you're asking I will suggest you to use you're arduino ide to program the Atmega using register names as shown on the official datasheet. Doing so you can start learn the internal parts of the micro and at the same time you can avoid buying an external programmer. But if really want to load you're program or hex file you have to buy an external programmer.
I hope that helped
PS if you are using the arduino ide and writing manually the registers remember not to set incorrectly the configuration registers because that will make you're Atmega useless and you will need to buy an external programmer.
Edit:
For better understanding you can refer to this link.
Programming arduino in c

So I can use it as any other programmer together with avrdude and avr-gcc! I don't want to use Arduino IDE, but random C libraries I may have for the ATmega328.  thanks a lot.

Yes, the Uno is designed to be very simple to program. The only extra hardware you need is a USB cable to connect it to your computer.
If you're completely new to this then the simplest way to start is by following the official "Getting Started" guide. Note that the section on drivers is particularly important.
The guide explains how to use the official Arduino IDE for programming the microcontroller. It automatically handles compiling and uploading your code via gcc and avrdude. It's technically configured to compile as C++ code, but plain C code should be fine too.
I don't recommend that IDE for long-term use though as it's really only aimed at beginners (it has a number of limitations and other problems). Using the command-line tools directly is certainly possible if you'd prefer that. However, you may also like to consider alternative IDEs which have support for Arduino plug-ins.


text:
Slaving multiple Arduinos via SPI
I am attempting to use SPI communication between a Master Arduino Mega 2560, and standalone Slave Arduino Unos (4, to be exact).
The intention is for the Unos to do some trivial work and produce one byte of data that the Master will take from it, whenever needed. They produce this byte very quickly, and the SPDR is updated with a holding variable (a byte) when the slave is interrupted. The Slaves do not take data from the Master.
The standalone platforms are working 100% (doing the work without problem), and using a single Slave to perform the work, create the byte of data, and have a Master take that data from it, is also working 100%.
The issue When all four slaves are connected (all being powered from the Master), all sharing the MISO, MOSI, and SCK lines, each with its own unique SS line, I am getting xFF for my data byte (garbage data) from the primary slave. I am using the default Mode 0, and the SCK lines are tied to ground via a 0.1uF capacitor (to smooth the clock signal)... All other SPI lines are wired directly.
The other three slaves are floating their MISO lines (third state), and the Master has all four SS lines as outputs, and all are pulled HIGH in the Master setup. The primary slave I am attempting to communicate with is SS connected to the main SS on the Master (pin 53 on a Mega). I pull the pin LOW, grab the byte from the Slave, and then pull the line HIGH... still garbage.. but only when all four slaves are 'hooked up', like I said, it works fine with one Master, one Slave.
Anyone have thoughts as to what I could be neglecting, missing, etc??

Here is the slave schematic. What you can't see is that VCC and AVCC are tied to the 5V line from the 10-pin header (the connection to the master).

The external power supply I am currently using is added in parallel to the 5V/Grnd you see in the schematic. The power supply has a max current draw at 5V of 10A, so I'm pretty confident that power is not my issue now, unless I have missed something.
I just realized that the imgur image is hard to see, here is a cut-away that should be clearer.

"and the SCK lines are tied to ground via a 0.1uF capacitor (to smooth the clock signal)" ... what? why? This is a terrible idea!

There's a good chance you're running into power regulation issues, too. The regulator on any Arduino has barely enough thermal capacity to power its own microcontroller chip, and burdening it with four other Arduinos is likely to be overloading the master's regulator.

I was wondering about that as well, but it was something I read when setting up initially. I HAVE re-tested without the capacitor connected.. no change.

I have also externally powered the primary slave, when testing, to check the possible power issue

At this point, I think we're going to need a detailed schematic of your setup, along with the code you're using for the SPI communications.

The master and slave code I am using, just for testing, is from the Gammon Forums, http://www.gammon.com.au/forum/?id=10892. The only addition is that the other 3 slaves are simply floating their MISO pins (dummy code). Also, the master is setting all SS high (as outputs, of course) in the setup.

*This should never have been migrated it's an EE question that belongs on the EE site, not here.

the SCK lines are tied to ground via a 0.1uF capacitor (to smooth the clock signal)

Get rid of that for a start.

The other three slaves are floating their MISO lines (third state)

That's your problem. They should all be outputs. From the datasheet:

When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is held low, the SPI is activated, and MISO becomes an output if configured so by the user. All other pins are inputs. When SS is driven high, all pins are inputs, and the SPI is passive, which means that it will not receive incoming data. Note that the SPI logic will be reset once the SS pin is driven high.

As you can see from that, you should configure all the MISO pins as outputs. However the SPI hardware will turn them into inputs if SS is high. Thus only one slave (the one you set MISO as an output) is capable of responding at present.
You should probably set them as outputs after turning on SPI slave mode. eg.
  // turn on SPI in slave mode
  SPCR |= bit (SPE);

  // have to send on master in, *slave out*
  pinMode (MISO, OUTPUT);

And generally, when you wonder about an Arduino-related topic, you check it out at Nick's website. eg http://www.gammon.com.au/spi It has become my habit to type http://www.gammon.com.au/ + whatever subject I want to learn more about as a a first choice...


text:
Using I2C: Master Reader and Writer
I'm using I2C and the Arduino Library (Wire) to communicate between two Arduinos, and my code isn't working. It's supposed to read in an int from the slave, write a value to the slave, then read back that value. I'm expecting "0 4", but i keep getting "0 0". Does this mean that the slave isn't registering the write?
Master code:
#include <Wire.h>

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  ffsis();
}

void ffsis()
{
  //request i
  Wire.requestFrom(2, 1);
  int i = Wire.read();
  Serial.print(i);

  //send n seed
  Wire.beginTransmission(2);
  Wire.write(12);
  Wire.endTransmission();

  Serial.print(" ");

  //request n
  Wire.requestFrom(2, 1);
  int n = Wire.read();
  Serial.print(n);
}

void loop()
{
  delay(100);
}

Slave code:
#include <Wire.h>

void setup()
{
  Wire.begin(2);
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

int n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{
  int n = wire.read();
}

int n = wire.read();

"Wire" should be capitalized.
Amplifying on Ken's reply, you have two variables called "n", and the global one should be declared volatile. Also, I2C deals in bytes, not ints, so preferably do this:
#include <Wire.h>

void setup()
{
  Wire.begin(2);
  Wire.onRequest(requestEvents);
  Wire.onReceive(receiveEvents);
}

void loop(){}

volatile byte n = 0;

void requestEvents()
{
  Wire.write(n);
}

void receiveEvents(int howMany)
{
  n = Wire.read();
}

In addition, the address 2 is a reserved address.

Address 0 is reserved as a "broadcast" address, addresses 1 to 7 are reserved for other purposes, and addresses 120 to 127 are reserved for future use.

You should choose an address in the range 8 to 119.
Reference

I2C - Two-Wire Peripheral Interface - for Arduino
Official I2C specification

Since you have
int n
in the receiveEvents function, you're making a new local variable, not using the global n variable.

Your answer is correct but it could be made better if you provided further explanations on variable scopes in C/C++, and maybe post the updated code.


text:
How to Display data from Strings?
I am working in an interactive project in displaying texts in POV which people can click to generate different texts automatically.
I wrote a String to store the text first, but it seems cannot display it.
Then I change the code to use char* to store the text, but it still does not work.
Can anybody help to solve this problem....?
char* myStrings[] = {
  "a", "c", "d", "f",
  "b", "e", "v", "B", "C"];

The code:
loop(){

  //xbee
  // potVal = analogueRead(potPin);
  // xbee.println(potVal);
  for (int t=0; i<sizeof(myStrings)-1; i++) {
    displayChar(myStrings[i];
  }
  for (int i=0;i<7; i++)
    digitalWrite(leds[i],LOW);
  delay(10);

You intend for myStrings to be an array of strings, or an array of c-strings (char*) , or an array of individual characters? the name suggents one thing, but displayChar(myStrings[i]); seems to suggest the other.

I intend to make myStrings an array of 9 char* ... store 9 characters... once arduino receive command from processing so it can display one of the character...but now it can not access to the data in myStrings ?                                                  char* myStrings [9] = { "a", "c", "d", "f", "b", "e", "v", "B", "C"};                        Sorry for the poor explanation...Any help would be greatly appreciated.

an individual character is just a char, a c-style string of one or more characters is a char*. I'm still not certian, do you want myStrings[i] to be the i'th single character from the string "acdfbevBC", or do you want it to be the i'th of 9 unrelated strings?

yes...I want myStrings[i] to be the i'th single character from the string "acdfbevBC"... but now I got confused with the code and I don't know how to correct it... Really appreciated for your help btw!

Like the error message says, each entry is a char*. Convert it to an array of characters instead.

First thing, in C++ (or C) a character in single quotes is just a single lone character, but any characters in double quotes is a string literal. for example "hello" is a const char[6] containing the characters 'w','o','r','l','d','\0'. That extra '\0' is the null terminator that makes an array of chars into a c-string.
Your code is making a variable
char* myStrings[] = { "a", "c", ... };

This is an array of char*, which means each element is a char*, which in turn means each element is a full string (in your case each has 2 characters).
You want an array of single characters, which means you either drop the * in char*, or drop the [] in myStrings[], and use either an array of single characters {'a','b',...}, or a single string literal "acdfbevBC". Any of these lines will work in your code:
const char * myStrings = "acdfbevBC";
char myStrings[] = "acdfbevBC";
char myStrings[] = { 'a', 'c', 'd', ... 'C', '\0'};

If you never plan to print myStrings as a unified string, you can leave off the '\0', the null terminator is there so functions that you pass it to know when it stops without you having to explicitly pass how long the string is.
Also, the first line is const char * because you should never overwrite a string literal. char myStrings[] is fine without const because the compiler is using the literal to initialize an array that gets its own place in memory, not making myStrings point into a separate cache of string literals.
Check out cpp reference's details here for more details on string literals.


text:
How to run Arduino 1.0.6 on OS X 10.10 with Java 7 or 8 already installed
On a new Mac (running OS X 10.10) with Java 7 or 8 already installed (for other development), how can I run the Arduino 1.0.6 IDE (which seems to be required for the LightBlue Bean BLE Arduino device), which seems to require using a very old Java 6 installer from Apple?
Is there a way to install multiple versions of Java without breaking any of them?  Or is there a way to use the Arduino 1.0.x IDE with a newer version of Java?
Or should I re-ask this question over at the apple.stackexchange.com site?

I think they have a special version of the IDE. https://punchthrough.com/bean/getting-started-osx/ . What error do you get when you run the app?

You can call java specifying each and every .jar to its -cp (classpath) parameter.
Sure you can't just use the latest 1.6.1? Or the current nightly, soon to become 1.6.2, which bundles java 8?

Reportedly the LightBlue SDK installation currently destroys an Arduino 1.6.x IDE.


text:
Don's NDEF library and bluetooth
I am trying to connect my Android smartphone with my Arduino Uno by sending a NDEF message to my phone.
I know that the MIME type for bluetooth is application/vnd.bluetooth.ep.oob but in my PN532 library I don't know what's the right prefix.
You can see prefixes here : https://github.com/Seeed-Studio/PN532/blob/master/PN532/PN532.h#L66
Thank you


text:
Linkit One- Connect rc522 rfid with linkit one
Linkit One is a board based in Arduino by mediatek.
I am trying to connect a rfid reader with it link
I am trying from past 3 days to get it working, checked my code wiring but nothing seems to get it working.
The reader is perfectly working because i tested it on raspberryPi and it worked flawlessly.
In my linkit board i am able to detect the reader but card is not getting scanned.
I am using this library GitHub
and my code is fairly simple one
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9   //
#define SS_PIN  10  //
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, type, and data blocks..."));
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
void ShowReaderDetails() {
// Get the MFRC522 software version
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print(F("MFRC522 Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (unknown)"));
Serial.println("");
// When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) {
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
}
}

This program in theory should detet reader and when card is scanned should display the UID.
I am getting msg that my card is v2, so its detecting the reader but not reading the card.

Same problem here. It seeems there is a problem writing to registers. the self test of the chip returns false.

This link worked for me:
http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt
Found it in a forum:

Please have a look at this ino file
  http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt
  this ino file works with my reader  but this rc522 library does not
  https://github.com/miguelbalboa/rfid  I want to know the difference as
  i was not able to spot any, one works and another does not.
Please let me know if there is any editing to be done so to get
  https://github.com/miguelbalboa/rfid this working

my friend, i have some problems with version 2.0 trying to read some cards. i think that the problem when  u cant read the card is this version . i have both version 1.0 and 2.0, version 1.0 detect all card type, and 2.0 some not.
for me is a big problem because, here in argentina i only found version 2.0. maybe change on library some.

This is not even an answer, its just going along with question.


text:
Send multiple int values from Python to Arduino using pySerial
I'm trying to send 3 ints in the range of 0-180 from Python to the Arduino Uno device using pySerial (py3K). I have managed to send 1 int by using python's struct lib (not sure if it's the best or fastest way but it works).
However I'm failing to send more than 1 and every example online seems to stop at 1.
Here's the simplified code. The task is to send servo0-servo4 to the Arduino and apply those values to the corresponding servos.
Python Code
import serial
import struct
import time

bge.arduino = serial.Serial('/dev/ttyACM0', 9600)

# let it initialize
time.sleep(2)

# send the first int in binary format
bge.arduino.write(struct.pack('>B', 45))

Arduino code
#include <Servo.h>
Servo servo0;
Servo servo1;
Servo servo2;

void setup(){
  Serial.begin(9600);
  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  if(Serial.available()){
    int message = Serial.read();
    // control the servo
    servo0.write(message);
  }
}

I guess I'll answer my own question for anyone else having this issue. What I did was:
Python:
# write to arduino as raw binary
bge.arduino.write(struct.pack('>BBB',45,90,180))

Arduino:
#include <Servo.h>

Servo servo0;
Servo servo1;
Servo servo2;

// create array
int incoming[2];

void setup(){
  Serial.begin(9600);

  servo0.attach(3);
  servo1.attach(5);
  servo2.attach(6);
}

void loop(){
  while(Serial.available() >= 3){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

You're not verifying if Serial.available() has 3 values available.  So it's going to get filled with -1's if there aren't.  Check to see how many bytes are in the receive buffer.

void loop(){
  if(Serial.available() >= 3){
    // fill array
    for (int i = 0; i < 3; i++){
      incoming[i] = Serial.read();
    }
    // use the values
    servo0.write(incoming[0]);
    servo1.write(incoming[1]);
    servo2.write(incoming[2]);
  }
}

Thank you @baldengineer. I'm now verifying like you proposed. However after a little while of playing with the program it completely messes up and I have to reboot the Arduino for it to work again. I suspect the ordering of the bytes might be shuffling?

Holly cow, I think I solved the problem by replacing if(Serial.available().. with while(Serial.available().. Does that make sense to you?


text:
Not able to receive the operation results from the slave after the command being sent by Master - SPI

Brief - I am using two arduino Uno's. One acts as a master and the other as slave using Arduino IDE.  Below is the Master Code:
// Taken from Nick Gammon's Forum//

#include "SPI.h"
#include"pin_arduino.h"
int ss = 10;
void setup()
  {
    pinMode(ss,OUTPUT);
    Serial.begin(9600);
    Serial.println();
    digitalWrite(ss,HIGH);
    SPI.begin();
    SPI.setClockDivider(SPI_CLOCK_DIV8);
   }
byte transferAndWait(const byte what)
 {
   byte a = SPI.transfer(what);
   delayMicroseconds(20);
   return a;
 }
void loop()
 {
   byte a,b,c;
   digitalWrite(ss,LOW);
   transferAndWait('a');
a = transferAndWait(17);
b =  transferAndWait(33);
c = transferAndWait(0);
digitalWrite(ss,HIGH);
Serial.println(a,DEC);
Serial.println(b,DEC);
Serial.println(c,DEC);
delay(1000);
 }

Before I go into the details of the results I obtained and the problem, below is the Slave code:
//Taken from Nick Gammon's Forum//

#include "SPI.h"
#include "pins_arduino.h"
int slave = 10;
int miso = 11;
byte c = 0;
void setup()
  {
    pinMode(miso,OUTPUT);
    pinMode(slave,INPUT);
    Serial.begin(9600);
    SPR|= BV_(SPE);
    SPR|= BV_(SPIE);
 }
ISR(SPI_STC_vect)
 {
   c = SPDR;
  switch(c)
    {
      case 0:
      SPDR = 0;
      break;

     case 'a':
     SPDR = c + 15;
     break;
   }
  }
  void loop(void)
   {
     if(digitalRead(slave)==HIGH)
     c = 0;
   }

My Results : After dumping the master and slave codes into their respective arduino uno's, then when I open the serial monitor of the master code, It displays the number 17, 33, 0 and the same goes with the slave, meaning that the data is being sent to the slave and received back successfully, and hence I presume the SPI bus is working properly!. But why isn't the add operation happening?
Problem: Now the problem is, when the command 'a' is sent from the master to the slave, the slave has to interpret this 'a' command as Addition command and perform the addition of a number 15 to the incoming byte from the master as shown in the slave code, and return the results to the master, which should display the addition results in the  masters serial monitor. I am having problem performing this task and looking forward to suggestions on how to test or where I am doing wrong or make changes to the code or methods in order to get this working. I am expecting answers relevant to the below codes and method.

Since I wrote that example, I'll try to answer this. First I tested with the code from my page about SPI.

SPI Master
This is the master:
#include <SPI.h>

void setup (void)
{
  Serial.begin (115200);
  Serial.println ();

  digitalWrite(SS, HIGH);  // ensure SS stays high for now

  // Put SCK, MOSI, SS pins into output mode
  // also put SCK, MOSI into LOW state, and SS into HIGH state.
  // Then put SPI hardware into Master mode and turn SPI on
  SPI.begin ();

  // Slow down the master a bit
  SPI.setClockDivider(SPI_CLOCK_DIV8);

}  // end of setup

byte transferAndWait (const byte what)
{
  byte a = SPI.transfer (what);
  delayMicroseconds (20);
  return a;
} // end of transferAndWait

void loop (void)
{

  byte a, b, c, d;

  // enable Slave Select
  digitalWrite(SS, LOW);

  transferAndWait ('a');  // add command
  transferAndWait (10);
  a = transferAndWait (17);
  b = transferAndWait (33);
  c = transferAndWait (42);
  d = transferAndWait (0);

  // disable Slave Select
  digitalWrite(SS, HIGH);

  Serial.println ("Adding results:");
  Serial.println (a, DEC);
  Serial.println (b, DEC);
  Serial.println (c, DEC);
  Serial.println (d, DEC);

  // enable Slave Select
  digitalWrite(SS, LOW);

  transferAndWait ('s');  // subtract command
  transferAndWait (10);
  a = transferAndWait (17);
  b = transferAndWait (33);
  c = transferAndWait (42);
  d = transferAndWait (0);

  // disable Slave Select
  digitalWrite(SS, HIGH);

  Serial.println ("Subtracting results:");
  Serial.println (a, DEC);
  Serial.println (b, DEC);
  Serial.println (c, DEC);
  Serial.println (d, DEC);

  delay (1000);  // 1 second delay
}  // end of loop

SPI Slave
And this is the slave:
// what to do with incoming data
volatile byte command = 0;

void setup (void)
{

  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);

  // turn on SPI in slave mode
  SPCR |= _BV(SPE);

  // turn on interrupts
  SPCR |= _BV(SPIE);

}  // end of setup

// SPI interrupt routine
ISR (SPI_STC_vect)
{
  byte c = SPDR;

  switch (command)
  {
  // no command? then this is the command
  case 0:
    command = c;
    SPDR = 0;
    break;

  // add to incoming byte, return result
  case 'a':
    SPDR = c + 15;  // add 15
    break;

  // subtract from incoming byte, return result
  case 's':
    SPDR = c - 8;  // subtract 8
    break;

  } // end of switch

}  // end of interrupt service routine (ISR) SPI_STC_vect

void loop (void)
{

  // if SPI not active, clear current command
  if (digitalRead (SS) == HIGH)
    command = 0;
}  // end of loop

Test results
Testing gave the expected results:
Adding results:
25
32
48
57
Subtracting results:
2
9
25
34

So, what is different in your code?
Your slave ISR:
ISR(SPI_STC_vect)
 {
   c = SPDR;
  switch(c)
    {
      case 0:
      SPDR = 0;
      break;

     case 'a':
     SPDR = c + 15;
     break;
   }
  }

This isn't quite the same, is it? In my code you get the command in one session (one interrupt) and what to use it for in another one.
Hence I had this:
  byte c = SPDR;

  switch (command)
  {
  // no command? then this is the command
  case 0:
    command = c;
    SPDR = 0;
    break;

Sending a "command" of zero clears the current command. So the sequence being sent is like this:
0    <-- start a new command
command  (ie. 'a' or 's')
22   <-- what to add to
33   <-- what to add to
44
55

Perhaps confusingly, I didn't send in that order, because I knew that the command would be zero initially(1), so I actually sent:
command  (ie. 'a' or 's')
22   <-- what to add to
33   <-- what to add to
44
55
0    <-- start a new command

There would be other ways of achieving this, but the fact is you changed the way the slave interpreted the incoming data.

I knew it would be zero because the slave sets the command to zero in the main loop if SS is not asserted.

ISR(SPI_STC_vect);  <-- Reason 1.
 {
   byte c = SPDR;
  switch(command)   <-- Reason 2.
    {                      |
      case 0:              |
      command = c;  <------┘
      SPDR = 0;
      break;

     case 'a':
     SPDR = c + 15;
     break;
   }
  void loop(void)   <--- Reason 3.
   {
     if(digitalRead(slave)==HIGH)
     command = 0;
   }

The slave code is not going to work, for various reasons.
Reason 1:
This is a declaration of a function. Not an implementation.
The ";" is badly misplaced here.
Reason 2: You're switching on a value "command" but it's only changed after executing the case/command?
Reason 3: The loop function is still part of the previous function?
The "{" below the ISR(SPI... isn't closed right. (With another "}")

The reason 1 and 3 were a typos, sorry about that!

Oh. Thank you for pointing out reason 2. Didn't notice that. I will shift this statement outside the case and check.

I edited the slave code as shown above. But my slave code is still not executing the " SPDR = c + 15" statement for case 'a'. Its repeatedly displaying 97,97,97.... on the serial monitor. Its just a simple add operation and I cant figure whats the mistake in the code, my master code seems to look fine. Pl help me debug.

Try to go back to the basics, verify that works and build on from there.
So first, make one arduino send stuff and let the other one print it as is.
No handling, just serial out it.
From there you can build on.
I believe SPDR is only 1 byte, so sending three bytes after eachother is quite weird? Because you check on the 'a' and then send it back +15... if another byte comes in, it will not be handled by the case switch..


text:
use arduino IDE for USB isp programmer
A few years ago I programmed AVR ATmega8 with AVR studio by USB isp programmer.
I was using C language. Now I would like to use arduino(C++) langauge and my external USB isp programmer. Is it possible?

What kind of programmer? What is the Model?

The Arduino IDE compiles and outputs standard Intel HEX format files that are compatible with (nearly?) all programmers. If you enable detailed logging in the preferences panel you can find out which directory the IDE is building your code in and if the IDE does not include specific support for your programmer you can then locate the .hex file and upload it using the tool you are familiar with. The projects are typically built in a build.* subdirectory under %TEMP% (or /tmp on unix).

If you want to use arduino IDE to program the atmega328 you don't need a USB ISP programmer. The only thing you have to do is load the arduino bootloader on the atmega328 in order to program it through the arduino IDE. In the ide you can program the board with c++. But if you want to program the atmega328 through you're USB ISP programmer (assuming it is capable of programming the Atmega 328) you have to use other IDE in which you can program in c++ and produce an hex file that can be burned on the chip through you're  programmer on the atmega328.

The programmers supported by the Arduino IDE are listed under Tools | Programmer. In order to upload your sketch using the programmer either Shift-click the upload button, select File | Upload Using Programmer, or press CtrlShiftU.


text:
Using XBEE from my laptop, I want to assign multiple values in the Arduino
I'm trying to control motors by Arduino, from my laptop. I'm using MATLAB to send over packets of data, i.e. 'x=100,y=150,z=200' My scheme was to send this packet to Arduino, and have Arduino extract the numerical values from the string, since the positions of the numbers will always be consistent. I found a code from Arduino forum, written by PaulS, but I can't figure out why it wouldn't move into 'if (xbee.available())' portion of the code. The code is attached below:

#include <SoftwareSerial.h>
#define SOP '<'
#define EOP '>'

SoftwareSerial XBee(2, 3); // RX, TX
int test = 0;
bool started = false;
bool ended = false;

char inData[20];
byte index;
char inChar;

void setup()
{
   XBee.begin(9600);
   Serial.begin(9600);
}

void loop()
{
  // Read all serial data available, as fast as possible
  while(Serial.available() > 0)
  {
    if (XBee.available())
    {
      char inChar = XBee.read();
     }
    if(inChar == SOP)
    {
       index = 0;
       inData[index] = '\0';
       Serial.print(inData);
       started = true;
       ended = false;
    }
    else if(inChar == EOP)
    {
       Serial.print(inChar);
       ended = true;
       break;
    }
    else
    {
      if(index < 19)
      {
        inData[index] = inChar;
        Serial.print(inData);
        index++;
        inData[index] = '\0';
      }
    }
  }

  // We are here either because all pending serial
  // data has been read OR because an end of
  // packet marker arrived. Which is it?
  if(started && ended)
  {
    // The end of packet marker arrived. Process the packet
    Serial.println(inData);
    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';
  }
}

what are your connection? This script use Serial AND Xbee, how did you connected them?

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Pixy Pet Robot stuck on uploading code
when I upload the code to my leonardo board it just stuck on uploading, like this:
could someone help me with this?

Is it a real Leonardo or a clone? If a clone, adding a reference would be welcome. Also, is it really connected to COM4?

I am sure it is connected to COM4. Actually, I use SparkFun RedBoard instead of Leonardo, but I also try to use Arduino Uno, it has the same problem.

First off, the sparkfun redboard  must be defined as a UNO in Arduino IDE, not Leonardo. Second; it uses FTDI drivers: did you install these?


text:
RFID library issue
I am having some strange issue. I am using Linkit One board, which is a based on Arduino.
I am using rfid reader RC522 which is cheapest and most common.
I cant get its official library get it work. I tried to search for problem or differences but nothing help. I am looking for some to take a fresh look because its been 4 days and i am stuck.
Not Working https://github.com/miguelbalboa/rfid
Working (this is full ino in single file) http://www.grantgibson.co.uk/blog/wp-content/uploads/2012/04/ggrfid_en_ino.txt


text:
setup() resets from loop, when I add parameters to http get `?identity=%2B0123456789&identityType=1`
I am trying to call a HTTP GET using my Arduino via SIM900A.
When I run the commands manually via the USB port, I am able to get the commands to run. Now, when I put the same sequence on arduino, the setup() is called repeatedly after the sendATcommand(httpAuthCommand, "OK", 2000);. Looks like a reset issue.
I read, this link to put all my code into loop to avoid the setup() reset issue. But seems like this is did not fix the issue.
I have debugged it to this one change.
This Works
char httpAuthCommand[] = "AT+HTTPPARA=\"URL\",\"http://www.m2msupport.net/m2msupport/http_get_test.php\"" ;

This Does Not work
char httpAuthCommand[] = "AT+HTTPPARA=\"URL\",\"http://1.1.1.1:8080/mytomcatservice/mypath/mycommand/Request?identity=%2B1234567890&identityType=1\"" ;

I debugged this a bit more, it does not work when I add ?identity=%2B0123456789&identityType=1 to the httpAuthCommand. Something crazy while sending parameters ??
In loop()
sendATcommand(httpAuthCommand, "OK", 2000);

sendATcommand method
int8_t sendATcommand(char* ATcommand, char* expected_answer, unsigned int timeout){

    uint8_t x=0,  answer=0;
    char response[100];
    unsigned long previous;
    memset(response, '\0', 100);    // Initialice the string
    delay(100);
    while( Serial.available() > 0) Serial.read();    // Clean the input buffer
    Serial.println(ATcommand);    // Send the AT command
    x = 0;
    previous = millis();
    // this loop waits for the answer
    do{
        // if there are data in the UART input buffer, reads it and checks for the asnwer
        if(Serial.available() != 0){
            response[x] = Serial.read();
            x++;
            // check if the desired answer is in the response of the module
            if (strstr(response, expected_answer) != NULL)
            {
                answer = 1;
            }
        }
    // Waits for the asnwer with time out
    }while((answer == 0) && ((millis() - previous) < timeout));

    return answer;
}

Raw commands work on Chrome

http://www.m2msupport.net/m2msupport/http_get_test.php
http://1.1.1.1:8080/mytomcatservice/mypath/mycommand/Request?identity=%2B918177900460&identityType=1

My Guess
I am missing some escape sequence characters in the command (especially in the parameters section ?identity=%2B0123456789&identityType=1).

"Something crazy while sending parameters ??"
Possibly your power supply is to weak so 5V drops low and the processor resets when the transmitter sends a message.

I have multimeter, can you tell me how to check for this to be true ? I do have a 1A power supply, and that may be the reason. What pin should I be checking for the power ?

I checked voltage between the Power Gnd, and Pin 55,56,57 of the sim900A. It reports a constant 3.9V.

1Amp is probably enough. your problem is something else then.

Could you have exceeded the rather limited RAM?
First experiment: Replace the added string with "xxx....x". If you have the same problem, then it's not the contents of the string but its length.
Second experiment (or jump straight to this one): Compile your strings in flash instead of in RAM. Note this will only help if you have a number of them, since your code will have to copy each one to RAM (at run-time) in order to use it, taking up some of the space you had saved. If there is only one string moved to flash, your code will need a temporary buffer of equal size (though only during the actual print call). A possible way around this is to break up the long string into a number of short ones, put all of them in flash, then print them sequentially at run time. That will need a buffer only as large as your largest substring. The cost will be increased use of flash, both for string storage and for the extra number of print calls; and slightly slower execution (probably not an issue).
This may be telling you that you need a more capable processor (one with more RAM space) or that you need to start getting creative about fitting your application into the one you've got.

Its a ATMEGA328, and code size is just 3kb. Total size of memory is 28kb.

It only has 2K of RAM, though, and that is usually its toughest limitation. We don't know for a fact that you're out of RAM but it's easy to use it up, and when you do, something gets over-written and the program crashes. Resetting is one possible effect of that.

Ok, Ill look into that and report back. My power supply just konked, power led is blinking like crazy. And my 9v power is dropping to 2v after I connect it to the SIM900A board. Regulator and SIM900A ic are heating up. I think there may be a short somewhere.


text:
Problem Bootloading AVR328P-PU
I executed the following steps in order to burn a bootloader into an  AVR328P-PU chip I acquired on ebay.

I have set up AVR328P-PU on a breadboard as described here: http://arduino.cc/en/main/standalone
I have uploaded the ArduinoISP sketch into Arduion Uno.
Connected the wires in a way described here http://arduino.cc/en/Tutorial/ArduinoToBreadboard ( the setup with external clock)
Chose "Tools -> Programmer -> Arduion as ISP" in the IDE.
Chose "Burn Bootloader" from the IDE.
Got and error avrdude: Yikes!  Invalid device signature., noticed that I connected the wires in the wrong order.
Fixed the wired, but still got the error:

avrdude: Version 6.0.1
     System wide configuration file is "C:\Program Files\Arduino/hardware/tools/avr/etc/avrdude.conf"

     Using Port                    : COM3
     Using Programmer              : stk500v1
     Overriding Baud Rate          : 19200
     AVR Part                      : ATmega328P
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PC2
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
       flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
       lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

     Programmer Type : STK500
     Description     : Atmel STK500 Version 1.x firmware
     Hardware Version: 2
     Firmware Version: 1.18
     Topcard         : Unknown
     Vtarget         : 0.0 V
     Varef           : 0.0 V
     Oscillator      : Off
     SCK period      : 0.1 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude: Device signature = 0x000000 (retrying)

Reading | ################################################## | 100% 0.05s

avrdude: Device signature = 0x000000 (retrying)

Error while burning bootloader.
Reading | ################################################## | 100% 0.07s

avrdude: Device signature = 0x000000
avrdude: Yikes!  Invalid device signature.
     Double check connections and try again, or use -F to override
     this check.

avrdude done.  Thank you.

My questions

I understand that this can be caused by poor breadboard quality. How can I test this hypothesis before buying new breadboard?
Could the wrong wiring from step 5 ruin the chip?

Did you try setting up a crystal?

@Ignacio Yes, I set it up exactly like in step 1.

Direct link to how the setup looks like: http://arduino.cc/en/uploads/Main/arduinobb_08.jpg

Are +5v and Gnd carried across the breadboard to both sets of power rails?  * In the article you linked, the Arduino provides power to the chip you're trying to program - so why is there a regulator on the breadboard? * If the regulator is the chip's power supply, is its input voltage high enough for it to regulate, and are the grounds of both supplies (the Arduino and your breadboard) board connected to each other? * To your question 2, Maybe yes ... exactly what were the wrongly ordered connections?

@JRobert I have uploaded photos of the setup. The regulator is there, but for the bootloader burning, I power the breadboard from the Arduino.  The wrongly ordered connection was swapping of the blue and yellow wires (SCK <-> MOSI). Could this ruin the chip?

My guess is no - I'd be more concerned of one of the swapped wires was the Arduino's +5v or there'd been some cross connection of the two power supplies.

On the Arduino Uno, you'll need to connect a 10 uF capacitor between reset and ground (after uploading the ArduinoISP sketch)

@Gerben Same error. But can you explain the reasoning behind the suggestion?

http://arduino.cc/en/Tutorial/ArduinoISP . Wiring seems fine, but the programmer can't see the chip (sign. 0x0000). Try wiggling the pins in the breadboard, to make sure they make good connection. What leds do light up? (Left constant, and right flickering during programming?)

Being from eBay, I would assume the seller "bricked" the chip beyond his/her capability to fix.  Fortunately, you know about stack exchange!
My immediate suggestion is to find, borrow or build a high-voltage programmer.  This is a special programmer that can un-brick the chip no matter what's been done to it. The concept is easy, but you need to protect the programmer's pins from the 12v reset signal.
Googling "avr high voltage programmer" gives several useful links.
I'll get the actual links when I get back to a real computer.
Ok, so life got in the way, sorry about that.
This is the one I built which worked perfectly:
MightyOhm
However hooking up the AVR to a "high voltage programmer" is well documented in the data sheets.  These should be very much similar circuits on Google.

I had this exact same problem.  It turned out that my atmega328p had the wrong fuses.  I am not sure how to solve the problem using the default ardiuino ide, however I was able to plug my ArduinoISP into a linux machine (just plug in the usb) and correctly profram the fuses on a slave atmega328p to solve the problem:
The guide here gets you started, however it missing some of the fuses:
http://heliosoph.mit-links.info/arduinoisp-reading-writing-fuses-atmega328p/
The full command to set the default fuses is something like this:
avrdude -P /dev/ttyACM0 -b 19200 -c arduino -p m328p -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efuse:w:0x05:m


text:
How do I implement a userspace bootloader on Arduino Due?
Is it possible to use a custom bootloader, that loads and executes a main program stored for example on an SD card? The idea is to make it possible to update the Arduino remotely.
I tried this with a bootloader, which writes the program into the flash storage with a 32KB offset and then uses a function pointer with that address (0x88000) to continue execution there. The 0x80000 is as far as I am informed the address offset of the flash storage. It can be written on Due boards with this library: https://github.com/sebnil/DueFlashStorage. The problem was that this just hasn't worked, the Arduino simply stopped responding after the function pointer being executed. I would appreciate any information or hints on this topic.

A solution of this type should be possible - but was your loaded program linked to execute at that address?  And did you come up with a scheme for handling interrupt vectors?  I believe on the ARM cortex you can change the address of the vector table.

The guys at Phoenard did just that with an AVR2560. They wrote a bootloader that loads and saves FLASH memory from/to the Micro-SD card. You can save HEX files on an SD card and then load one of them in the FLASH memory and run it.

Not sure if you could get the bootloader to support SD, but I have little experience with bootloader code, so the way I would go about it would be to make the sketch load content from the SD that then affects the sketch process.

That sounds like what the poster already did.  To be an answer, this would need to provide a path around the fact that it didn't work - by being more than just a vague idea.


text:
How can I execute a shell command?
This page says to run a shell command I need a "proxy code" running on my computer (Linux Ubuntu). What do they mean by this, and how should I make one?

I'm not familiar with the term proxy code, but I'm assuming that it's a piece of code on your computer that acts as a man in the middle.
You cannot directly use Arduino to run a shell command, so you'll need to create a program on your computer that listens to serial and then executes a command.
For the "proxy code" Python would be a good choice because of the pySerial library that plays nicely with Arduino. It seems fairly easy to execute a shell command with Python.
As per the Arduino code, something like this would work good:
setup() {
  Serial.begin(9600);
}

loop() {
  if(state == true) {
    Serial.print('A');
  }
}

Some should direct the Pythonic Side Too


text:
Using interrrupts with RC522

I have a project using the RC522 RFID module with my Arduino Uno board and miguelbalboa's rfid library. The example code and every other code I find on the internet work pooling the device in order to know if there is a new card present, but I intend to work with a interrupt-driven approach. I have the proper knowledge to do the hardware/arduino part, but I'm having trouble generating an interrupt in the IRQ pin when the card is present. Have anyone succeded on this?
Edit:
Connection:
RST -> 8
SS-> 9
MOSI -> 11
MISO -> 12
SCK -> 13
IRQ -> 2
Code:
#include <SPI.h>
#include <MFRC522.h>
#include <String.h>

#define RST_PIN     8
#define SS_PIN      9

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

void setup()
{
  Serial.begin(9600);       // Initialize serial communications with the PC
  while (!Serial);      // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();       // Init MFRC522
  mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
  mfrc522.PCD_WriteRegister(MFRC522::ComIEnReg, 0x7F); //Enable all interrupts
  mfrc522.PCD_WriteRegister(MFRC522::DivIEnReg, 0x14);
  Serial.println(F("Ready..."));
  attachInterrupt(0, isr, RISING);
}

void loop()
{
}

void isr()
{
  Serial.println(F("Interrupt"));
  mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
}

Result:
I only get the "Ready..." on the Serial Monitor, no matter if there is a card present or not.

Welcome to Arduino SE! Code? Wiring?

@AnnonomusPenguin I have only used the example codes and wiring from the link (minor change, RST -> pin 8 and SS -> pin 9, for compatibility with the ethernet shield). As I haven't got access to an oscilloscope right now, I'm unable to check the interrupt pin, so I wrote a sketch to pool this pin and print its state via serial, 3-line code. It keeps giving me 0, no matter if the card is present or not... The documentation link says little about the interrupts and they're relation to the card reading.

Does that code deal with interrupts itself or have you modified it?

The library doesn't deal with the interrupt, they don't even use the IRQ pin...

So you did modify the code? Can you please add a minimal example of the problem (with the code and a circuit) to your question with an edit? Thanks

@AnnonomusPenguin edited...

You're going to have to do all the work yourself, because it seems nobody else has yet! First of all you need to work out the characteristics of the IRQ pin. Write a simple program, with no ISR or anything fancy, that just polls the IRQ pin and turns the onboard LED on when it's high, and off when it's low. If nothing happens, it could be because the IRQ is a pulse that's too short to see. Make a one shot program that waits until IRQ goes high (or low), then loops with the LED on.  You might have to enable the internal pullup resistor on the Uno. Good luck...

From your code:
void isr()
{
  Serial.println(F("Interrupt"));
  mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
}

Do not do serial prints inside an ISR! They will eventually hang it. What you need to do is have a volatile variable (eg. a bool), set that in the ISR, and then check that in loop. If it changes, display it. Eg.
volatile bool cardPresent;

void loop()
{
  if (cardPresent)
    {
    Serial.println(F("Interrupt"));
    mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
    cardPresent = false;
    }

}

void isr()
{
  cardPresent = true;
}

The other thing I would do is put a scope or logic analyzer on the IRQ pin and see if it is actually changing. It should trigger the interrupt if it does.

I'm quite late to this party, but I was looking for a way to have the MFRC522 generate an interrupt when it detects a compatible RFID card/key fob/sticker/etc., and this is one of the hits I got from my search. I write this now for the pilgrim who follows the same breadcrumbs I have in the hopes that it will save them at least a little time.
I tried something similar to what was suggested, found that I got interrupts quite often and continuously, and looked into the situation a bit more.
The MFRC522 does not generate interrupts for card detection. The microcontroller (or microprocessor) must command it to transmit and then query it to see if there was any response. This means that the MCU cannot go into a sleep mode and get awaken by the MFRC522 when there's a card to read.  The MFRC522 does have a timer that can generate an interrupt, but the maximum period of this timer is not huge, and the timer does not control the transceiver, it's there for the convenience of the application on the MCU.
Writing 0x7F to the "ComIEnReg" means the following:

Bit 7: IRqInv=0 - Interrupts are active high
Bit 6: TxIEn=1 - Transmitter interrupt is enabled
Bit 5: RxIEn=1 - Receive interrupt is enabled
Bit 4: IdleIEn=1 - Idle interrupt is enabled
Bit 3: HiAlertIEn=1 - "High Alert" interrupt is enabled
Bit 2: LoAlertIEn=1 - "Low Alert" interrupt is enabled
Bit 1: ErrIEn=1 - Error interrupt is enabled
Bit 0: TimerIEn=1 - Timer interrupt is enabled

The bits in the register "ComIrqReg" have the following meaning:

Bit 7: Set1 - when written as 1, a bit value of 1 in bits 6-0 of the byte written set the corresponding register bit; when written as 0, bits 6-0 clear the corresponding register bit
Bit 6: TxIRq - Set when the last bit of Tx data has been sent
Bit 5: RxIRq - Set when the receiver detects the end of a valid data stream
Bit 4: IdleIRq - Set when the CommandReg changes the command field to the idle command
Bit 3: HiAlertIRq - Set when the Status1 register HiAlert bit is set
Bit 2: LoAlertIRq - Set when the Status1 register LoAlert bit is set
Bit 1: ErrIRq - Set when any bit in ErrorReg gets set
Bit 0: TimerIRq - Set when the TCounterValReg decrements to zero

Writing 0x14 to the "DivIEnReg" has the following meaning:

Bit 7: IRQPushPull=0 - IRQ is an open-drain output pin
Bit 6: reserved=0 - no known effect
Bit 5: reserved=0 - effect unknown
Bit 4: MfinActEn=1 - Allow the MFIN active interrupt request to trigger IRQ
Bit 3: reserved=0 - boundedly undefined
Bit 2: CRCIEn=1 - Permit the "DivIrqReg" bit CRCIRq to trigger IRQ
Bit 1: reserved=0 - do not set to 1 on pain of nothing
Bit 0: reserved=0 - has no purpose other than to confuse

The register "DivIrqReg" corresponds to "DivIrqEn", and has the following bit definitions:

Bit 7: Set2 - when written as 1, a bit value of 1 in bits 6-0 of the byte written set the corresponding register bit; when written as 0, bits 6-0 clear the corresponding register bit
Bit 6: reserved - don't ask
Bit 5: reserved - don't tell
Bit 4: MfinActIRq - MFIN is active
Bit 3: reserved - just leave it at zero and back away slowly
Bit 2: CRCIRq - when 1, the CalcCRC command is active and all data is processed
Bit 1: reserved - nothing to see here
Bit 0: reserved - are you feeling lucky, punk?

The above register bit definitions were cribbed from the MFRC522 datasheet from NXP, titled "MFRC522 Standard performance MIFARE and NTAG frontend", Rev 3.9, 27-April-2016.
The library for the MFRC522 does have an interrupt example that uses a lighter weight means of polling the transceiver. see https://github.com/miguelbalboa/rfid/tree/master/examples/MinimalInterrupt, but it does not provide a means of waking your host from a low-power sleep mode when someone waves their magic ring over the hidden panel by the secret door, meaning that your secret lair will need to be wired to power the reader even if it is otherwise wireless; either that, or your henchmen will be forever changing batteries.

first of all, I apologize for the English, I can understand it but i use google translator to express myself in.
I don't use arduino, It's a interesting platform (for the ide, which is apparently object oriented programming POO), but extremely limited by the hardware
Well, entering the subject, I am also developing an implementation for the MRFC522, and the datasheet does not give examples of how do it, but indicates how enable interrupts (although I have not tried ,yet)
but if I'm not wrong, the following registers are involved:
ComIEnReg--> Control register bits to enable and disable the passing of interrupt requests.
DivIEnReg--> control bits to enable and disable the passing of interrupt requests.
ComIrqReg--> register Interrupt request bits. (I think it's read only)
DivIrqReg--> register bit descriptions (I think it's read only)
I think it's just properly setting the first two should be able to generate the interrupt on the pin irq.
i don't know if the following is correct.
set ComIEnReg to --> (in binary) 0b01111111 //enables all al interrupts
set DivIEnReg to --> 0b10000100  //I don't understand complete about MFIN (bit4) and set it to 0  but i set CRCIEn to 1 (bit 2) and bit7  to 1 "pin IRQ is a standard CMOS output pin"
// the different posible configuration to DivIEnReg

yours--> 0b00010100 -->0x14
try 1 --> 0b00000100 -->0x04
try 2 --> 0b10010100 -->0X94
try 3 --> 0b10000100 -->0X84

if you manage to the module to do the interruption, it would be kind enough to comment on how you did

Unfortunatelly I was unable to use the IRQ pin. My project is stopped right now but I'll get back to it in a little and maybe figure it out. I'm pooling the module to check for a new tag for now and for what I read back then seem like no one was able to use the interruption to detect new tags. I agree with you on the Arduino, it's very limited but as I'm only working on a POC (proof of concept), is the perfect platform!

As you mentioned "Arduino is limited" can you share other alternatives. Would like to explore them as-well.
I am completely from the software side, and would like to understand this more.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Arduino Uno (master) and ATTiny85 (slave) I2C connection not working
I am trying to send and receive data using I2C between an Arduino Uno and an ATTiny85. The Arduino Uno is using the Wire library. The ATTiny85 is using the TinyWire library and is programmed (and powered) using the Sparkfun Tiny AVR Programmer.
I am not receiving any data.
Arduino Uno I2C master code
#include <Wire.h>

#define SLAVE_ADDR 0x50

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  Wire.requestFrom(SLAVE_ADDR, 1);

  while(Wire.available())
  {
    byte byteReceived = Wire.read();
    Serial.println(byteReceived, DEC);
  }
}

ATTiny85 I2C slave code
#include "TinyWireS.h"

#define SLAVE_ADDR 0x50

void setup()
{
  TinyWireS.begin(SLAVE_ADDR);
  TinyWireS.onRequest(requestEvent);
}

void loop()
{
}

void requestEvent()
{
  byte byteToSend = 23;
  TinyWireS.send(byteToSend);
}

I modified your Uno sketch slightly to add a delay:
#include <Wire.h>

#define SLAVE_ADDR 0x50

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  Wire.requestFrom(SLAVE_ADDR, 1);

  if (Wire.available())
  {
    byte byteReceived = Wire.read();
    Serial.println(byteReceived, DEC);
  }

 delay (1000);
}

Upon testing, it worked perfectly!
23
23
23
23
23
23
23
23
23
23
23
23

I suggest a wiring error. Check you have:
Uno    ATtiny85
--------------------
A4      pin 5  (SDA)
A5      pin 7  (SCL)
+5V     pin 8
Gnd     pin 4

I think the problem is (assuming you've got the pins straight) is that there's no time for the byte to get to the Uno.  Try while(!Wire.available()) between requestFrom... and the while(Wire.available())

Wire.requestFrom does not return until data is available, or if the slave device cannot be found. It returns the numbers of bytes available.


text:
Arduino UNO capacitive sensor not working
This is a visualization of my Arduino connections:

I wish to read the data using the Capacitive sensor Library. iv'e tried the following code but variables total1, total2, total3 always have the value 0 and i don't know what is wrong.
My code:
// Import the CapacitiveSensor Library.
#include <CapacitiveSensor.h>

// Name the pin as led.
#define speaker 11

// Set the Send Pin & Receive Pin.
CapacitiveSensor   cs_2_3 = CapacitiveSensor(2,3);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_5 = CapacitiveSensor(2,5);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_6 = CapacitiveSensor(2,6);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_7 = CapacitiveSensor(2,7);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_8 = CapacitiveSensor(2,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_9 = CapacitiveSensor(2,9);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

void setup()
{
  cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example

  // Arduino start communicate with computer.
  Serial.begin(9600);
}

void loop()
{
  // Set a timer.
  long start = millis();

  // Set the sensitivity of the sensors.
  long total1 =  cs_2_3.capacitiveSensor(60);
  long total2 =  cs_2_4.capacitiveSensor(60);
  long total3 =  cs_2_5.capacitiveSensor(60);
 /* long total4 =  cs_2_6.capacitiveSensor(60);
  long total5 =  cs_2_7.capacitiveSensor(60);
  long total6 =  cs_2_8.capacitiveSensor(60);
  long total7 =  cs_2_9.capacitiveSensor(60);*/

  Serial.print(millis() - start);        // check on performance in milliseconds
  Serial.print("\t");                    // tab character for debug windown spacing

  Serial.print(total1);                  // print sensor output 1
  Serial.print("\t");                    // Leave some space before print the next output
  Serial.print(total2);                  // print sensor output 2
  Serial.print("\t");                    // Leave some space before print the next output
  Serial.print(total3);                  // print sensor output 3
  Serial.print("\t");                    // Leave some space before print the next output
  Serial.print("\n");
}

What is the performance(i.e., how much time does it take to complete the procedure)?

i just wnna know if you got this code to run? i wanna try this project out. :)

Yes I run this, I only change board.

As found on the Capacitative Sensor Library page (emphasis added):

Use a 1 megohm resistor (or less maybe) for absolute touch to activate.
With a 10 megohm resistor the sensor will start to respond 4-6 inches away.
With a 40 megohm resistor the sensor will start to respond 12-24 inches away (dependent on the foil size). Common resistor sizes usually end at 10 megohm so you may have to solder four 10 megohm resistors end to end.
One tradeoff with larger resistors is that the sensor's increased sensitivity means that it is slower. Also if the sensor is exposed metal, it is possible that the send pin will never be able to force a change in the receive (sensor) pin, and the sensor will timeout.
Also experiment with small capacitors (100 pF - .01 uF) to ground, on the sense pin. They improve stability of the sensor.

The two emboldened points suggest that for a touch-piano, it would likely be advantageous to use a lower value resistor such as 1MΩ. Because the sensitivity increases as the resistor value increases, you want to use the lowest possible resistor value to reduce jitter & interference among your signal wires.

Also, later on the page:

The grounding of the Arduino board is very important in capacitive sensing. The board needs to have some connection to ground, even if this is not a low-impedance path such as a wire attached to a water pipe.

Ensure the Arduino is not run from a battery or unplugged laptop. For capacitative sensing to work, a stable ground connection is needed (via a DC plugpack or USB wall-wart is fine).
As a general note, try testing with only one capacitative connection first, then when that works, re-add the others.


text:
Arduino 1.6.1 IDE with Teensyduino Serial port lag issue?
OS: Ubuntu 14.04
Board: Teensy 3.1 and Arduino UNO
I've ran many tests and concluded that the issue is within the Arduino IDE itself.
The issue: Instead of a smooth stream of data displaying from the serial port, the terminal displays big chunks of data periodically.
I tested it with minicom and the stream of data is smooth.
Any solutions?

how fast is 'periodically'? I'm not surprised minicom is better, but unless the arduino terminal is really broken I don't think there is anything to fix.

around once per second.


text:
How can I use a BlueSMIRF Silver (RN-42) as a HID Keyboard (on IOS)?
I've got a BlueSMIRF Silver (RN-42) Bluetooth module.
I am trying to create a basic keyboard I can play with on an iPad Air.
At the moment barely manage to get the module to pair with OSX
but only through using Bluetooth Setup Assistant and using "Passcode Options...use a specific code".
With this option, the module pairs, but the connection resets about every 5 seconds.
On iPad it tries to use a generate number really fast and fails straight away, being unable to connect.
I noticed there is a BlueSMIRF HID version, but from what I can tell, the hardware is the same,
just the firmware is different. I've gone through the whole Bluetooth Data Module Command Reference & Advanced Information User’s Guide(pdf link) manual and from what I can gather,
even though I have Silver firmware burned onto my module, I should be able to set and use the HID profile
(from the default SPP):

Roving Networks modules shipped with firmware version 6.11 and higher
  support the HID profile. You do not need special firmware if your
  module is running firmware 6.11 or higher.

and my module reports version as:
Ver 6.15 04/26/2013
(c) Roving Networks

I've also gone through the Bluetooth HID Profile(pdf link) guide from Roving Networks, but the same information is present in Chapter 5 of the advanced user's guide mentioned above.
I've setup the following settings (with commands used):

HID Profile (S~,6)
Device discovery and pairing is set to automatic, without using GPIO6(SM,6)
HID Flag is set to Keyboard (SH,0000)
Authentication is set to open (SA,0)

I've also tried the inquiry scan(SI,0800)  and page scan(SJ,0800)  windows to maximum
in the hope it would increase the odds of successful pairing and made sure I rebooted the module and checked the settings again.
I have used the same module with the SPP profile just fine, but I'm still fairly new to Bluetooth
and this is the first time I try to use the HID profile.
How can I use the BlueSMIRF Silver as a basic Bluetooth Keyboard for an iPad Air ?

I should be able to set and use the HID profile (from the default SPP)

Unfortunately, your assumption is incorrect. From the same documentation you quoted, the previous sentence says:

To use Roving Networks’ Bluetooth HID profile, you must use a special
  build of firmware, version 6.03 or later.

Poorly phrased, this does mean that you need to have two things:

A special HID firmware
Version 6.03 or later

Your BlueSmirf Silver only complies with the second condition; it does not have the special HID firmware (also note that the Rovnix command reference does not address a specific variant of the BlueSmirf, but speaks generally about all of the variants).
The SPP protocol (Serial Port Profile) is used for emulating a serial cable, and functions as a substitute for the physical RS-232 connection, but cannot stack pure HID profile on top of it. In order for you do talk HID, you will need the HID firmware.
As a side note, the HID version comes with SPP and you can switch between the two modes interchangeably, I have been using the HID version for a while now and it works fine (including the pairing with iOS).
Another misfortune is that it does not appear that Roving Networks officially support any re-flashing of the BlueSmirf firmware, so unless you are willing to reverse the hardware, this is off the table as well.

Thanks Omer, very helpful(+1). I thought that I can get away just because the firmware is version 6.15, which is greater than 6.11 although I don't have the HID firmware. I found a blog post explaining how to capture and rewrite firmware, but I'm not experienced enough to risk it. I'm returning the Silver and getting an HID replacement (same price, same hardware, different firmware)

Happy to hear. Can you please post the link? might help others.

No worries, here what I found on Byron's Blog on flashing a new firmware and I got there from this post. I haven't tried this myself though, but it looks good

In the comments on SparkFun's product page for RN-42, gskelly indicates there is a flag in the v6.15 firmware that allows you to switch back and forth easily:

Actually, since this includes the v6.15 firmware, you don’t need to
  re-flash the module to switch between HID and SPP. It can now be done
  using AT commands as follows:
S~,6    // Enable HID on reboot
R,1     // Reboot
S~,0    // Enable SPP on reboot
R,1     // Reboot

I will try this again when I get my hands on another module. I do clearly remember trying the HID flag (S~,6) as I mentioned in question and it didn't work in my case.

I would be interested to know if it works. I found your question and this answer while I was looking for someone else, so I thought I'd try to connect the dots.

I know I am late to the party but for others searching this topic:
"S~,6" command does work for switching to HID profile but it requires the reboot command "R,1" otherwise it won't take.
I send these commands from the microcontroller to RN42 whilst the RN42 is in command mode, just to be clear.