text:
2.4" TFT LCD Shield isn't working on Arduino Mega
Even on ebay's website it is mentioned that I can't use 2.4" TFT LCD Shield display on attach to Arduino Mega. The problem is that I bought this shield by mistake. I want to put this shield onto Arduino Mega 2560. Is there a way to combine Mega and 2.4" Display Shield?
note: I tried on my friend's Arduino Uno. Shield is working very good.
note: The photo below is determining my question. The display not runs my Arduino's code. It only runs its LED.

    // UTFT_Demo_320x240 (C)2012 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// This program is a demo of how to use most of the functions
// of the library with a supported display modules.
//
// This demo was made for modules with a screen resolution
// of 320x240 pixels.
//
// This program requires the UTFT library.
//

#include <UTFT.h>
#define ILI9320_16 18
// Declare which fonts we will be using
extern uint8_t SmallFont[];

// Uncomment the next line for Arduino 2009/Uno
//UTFT myGLCD(UNO_24,A2,A1,A3,A4);   // Remember to change the model parameter to suit your display module!

// Uncomment the next line for Arduino Mega
UTFT myGLCD(ILI9320_16,38,39,40,41);   // Remember to change the model parameter to suit your display module!

void setup()
{
  randomSeed(analogRead(0));

// Setup the LCD
  pinMode(A0,OUTPUT);       // for the UNO_SHIELD_1IN1
  digitalWrite(A0,HIGH);    // the RD pin must be set high
  myGLCD.InitLCD();
  myGLCD.setFont(SmallFont);
}

void loop()
{
  int buf[318];
  int x, x2;
  int y, y2;
  int r;

// Clear the screen and draw the frame
  myGLCD.clrScr();

  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRect(0, 0, 319, 13);
  myGLCD.setColor(64, 64, 64);
  myGLCD.fillRect(0, 226, 319, 239);
  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
  myGLCD.setBackColor(64, 64, 64);
  myGLCD.setColor(255,255,0);
  myGLCD.print("<http://electronics.henningkarlsen.com>", CENTER, 227);

  myGLCD.setColor(0, 0, 255);
  myGLCD.drawRect(0, 14, 319, 225);

// Draw crosshairs
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);
  for (int i=9; i<310; i+=10)
    myGLCD.drawLine(i, 117, i, 121);
  for (int i=19; i<220; i+=10)
    myGLCD.drawLine(157, i, 161, i);

// Draw sin-, cos- and tan-lines
  myGLCD.setColor(0,255,255);
  myGLCD.print("Sin", 5, 15);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,0,0);
  myGLCD.print("Cos", 5, 27);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95));
  }

  myGLCD.setColor(255,255,0);
  myGLCD.print("Tan", 5, 39);
  for (int i=1; i<318; i++)
  {
    myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180)));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);
  myGLCD.setColor(0, 0, 255);
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.drawLine(159, 15, 159, 224);
  myGLCD.drawLine(1, 119, 318, 119);

// Draw a moving sinewave
  x=1;
  for (int i=1; i<(318*20); i++)
  {
    x++;
    if (x==319)
      x=1;
    if (i>319)
    {
      if ((x==159)||(buf[x-1]==119))
        myGLCD.setColor(0,0,255);
      else
        myGLCD.setColor(0,0,0);
      myGLCD.drawPixel(x,buf[x-1]);
    }
    myGLCD.setColor(0,255,255);
    y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100)));
    myGLCD.drawPixel(x,y);
    buf[x-1]=y;
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled, rounded rectangles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20));
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some filled circles
  for (int i=1; i<6; i++)
  {
    switch (i)
    {
      case 1:
        myGLCD.setColor(255,0,255);
        break;
      case 2:
        myGLCD.setColor(255,0,0);
        break;
      case 3:
        myGLCD.setColor(0,255,0);
        break;
      case 4:
        myGLCD.setColor(0,0,255);
        break;
      case 5:
        myGLCD.setColor(255,255,0);
        break;
    }
    myGLCD.fillCircle(100+(i*20),60+(i*20), 30);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some lines in a pattern
  myGLCD.setColor (255,0,0);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(1, i, (i*1.44)-10, 224);
  }
  myGLCD.setColor (255,0,0);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(318, i, (i*1.44)-11, 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=224; i>15; i-=5)
  {
    myGLCD.drawLine(1, i, 331-(i*1.44), 15);
  }
  myGLCD.setColor (0,255,255);
  for (int i=15; i<224; i+=5)
  {
    myGLCD.drawLine(318, i, 330-(i*1.44), 224);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random circles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=32+random(256);
    y=45+random(146);
    r=random(30);
    myGLCD.drawCircle(x, y, r);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRect(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

// Draw some random rounded rectangles
  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(207);
    x2=2+random(316);
    y2=16+random(207);
    myGLCD.drawRoundRect(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<100; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    x=2+random(316);
    y=16+random(209);
    x2=2+random(316);
    y2=16+random(209);
    myGLCD.drawLine(x, y, x2, y2);
  }

  delay(2000);

  myGLCD.setColor(0,0,0);
  myGLCD.fillRect(1,15,318,224);

  for (int i=0; i<10000; i++)
  {
    myGLCD.setColor(random(255), random(255), random(255));
    myGLCD.drawPixel(2+random(316), 16+random(209));
  }

  delay(2000);

  myGLCD.fillScr(0, 0, 255);
  myGLCD.setColor(255, 0, 0);
  myGLCD.fillRoundRect(80, 70, 239, 169);

  myGLCD.setColor(255, 255, 255);
  myGLCD.setBackColor(255, 0, 0);
  myGLCD.print("That's it!", CENTER, 93);
  myGLCD.print("Restarting in a", CENTER, 119);
  myGLCD.print("few seconds...", CENTER, 132);

  myGLCD.setColor(0, 255, 0);
  myGLCD.setBackColor(0, 0, 255);
  myGLCD.print("Runtime: (msecs)", CENTER, 210);
  myGLCD.printNumI(millis(), CENTER, 225);

  delay (10000);
}

The eBay ad has this nonsensical statement: "This shield does NOT work with the Mega Arduinos but its going to be half the speed of the Uno-type boards because of the way the Mega rearranges all the pins (there is no way to get around this!)"  How can it simultaneously not work, and be half speed?

Are you using the 8bit or the 16bit version?

You code says to use pins 38-41 while looking at the picture the shield doesn't even connect to pins 38-41. You are also defining a different lcd-model for the Mega than for the UNO. Try using the same code as the uno; so UTFT myGLCD(UNO_24,A2,A1,A3,A4);

You can use the MEGA2560 and an Arduino UNO interchangeably.  They run at the same speed, and they have the same pinouts and pin definitions.  if it works on a UNO, then it works on a MEGA

I just happened to buy the same LCD Shields a few days ago, looking for a library to use it with a MEGA 2560 board I found https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code which supports both UNO and MEGA boards.
Usage is very, simple if we want to use it for MEGA we should change the header #include "uno_24_shield.h" in SWTFT.cpp to #include "mega_24_shield.h"
Description (useful for adding suppport for the shield in other libraries):
Incompatibility comes from different Port mappings for Arduino pin-out between Mega and UNO.
in UNO LCD shield will be connected through:
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| LCD Data Bit  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Digital pin # |  7  |  6  |  5  |  4  |  3  |  2  |  9  |  8  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Uno port/pin  | PD7 | PD6 | PD5 | PD4 | PD3 | PD2 | PB1 | PB0 |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+

in MEGA it will be connected through:
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| LCD Data Bit  |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| Digital pin # |  7  |  6  |  5  |  4  |  3  |  2  |  9  |  8  |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+
| MEGA port/pin | PH4 | PH3 | PE3 | PG5 | PE5 | PE4 | PH6 | PH5 |
+---------------+-----+-----+-----+-----+-----+-----+-----+-----+

OH MY GOD!! IT IS WORKING :D First I download Arduino Enhanced Release 1.0.5 from here: http://forum.arduino.cc/index.php/topic,118440.0.html Then I opened your GitHub code then download it. I open swtft.cpp via DevC/C++ program I downloaded before. I change uno lines with these: #include "mega_24_shield.h" then I upload the code into Mega and it worked. I only put the 2.4" TFT LCD onto MEGA, I didn't make more nothing connection. Just I put the shield onto Mega :D God saves you :D Very special thank you. The error has been still for 6 months. Thanks.

A way to proceed is to create a spreadsheet showing the pin positions used by this board, and the Arduino shield signals they plug into. Next to these, you need columns showing the actual signals on the ATMega2560 (for Mega2560) and ATMega328 (for Uno) that these shield pins attach to. You can get this info from the Uno and Mega2560 schematic drawings.
In a quick look, it seems that the Arduino shield pin names for Uno and Mega are the same: for example, shield pin '0' (digital zero) is in the same location on both boards, and likewise for other pins.
However, on the Uno digital-0 attaches to ATMega328 Port D bit 0, while on the Mega2560, it attaches to ATMega2560 Port E bit 0. And things get more obtuse with digital 2..7.
Now, when twiddling bits individually using digitalWrite(pin, value), the Arduino library no doubt takes care of translating to the appropriate port/bits that need to be set for the ATMega chip and Arduino board that's in use. However, libraries that use lower-level functions (especially if they need to write entire bytes to ports, as a fast LCD library might) will need to take their own steps to make this translation.
So... first step is to determine whether there is a separate LCD driver library for Mega2560.
Next, investigate whether the library you have has initialization code that is supposed to determine what board it's running on (and is your board included?), or requires you to set some flag to tell it what board is in use.
Failing that, you could create a mess of jumpers or some other wiring scheme to jumper the Mega's ATMega2560's signals so that it's wired up like a Uno would be. It's not clear that this is possible, since some of ATMega2560's Port D is not even wired to a header.
Or you could look at the source code for the library and see what it's actually doing, and what it would need to do different to operate the ATMega 2560 pins that the shield does connect to.

Have you checked out the Library homepage? Henning Karlsen's library page
He has made a user manual for the library. There is also a reference to what pin goes where in the requirements document.

You need to compare the pins' functions between your Mega and your friend's Uno. Then you need to make those electrical connections happen. I talk about this a little in the "pin locations" section of my answer here.
This requires "hacking". Something needs to be done to reroute those physical connections. I normally use an intermediate shield to translate pins as needed. There was a shield specifically made for this purpose but I couldn't find it. Maybe this one would work?

SPI isn't a problem, as the shield is using D0-D7 picture. What other things could affect this?


text:
How to read code from Arduino Uno to Arduino IDE?
we can upload a code into Arduino UNO from our computers, but how about reading code? Can we read and get C codes from compiled codes from Arduino hardwares? My second question is that will we read these compiled codes on Arduino ZERO's debug port, which will be a new product for us as developers?

Can we read and get C codes from compiled codes from Arduino hardwares?

While it is possible, even trivial, to disassemble machine code, it is very difficult to convert the assembly code into a higher-level language, and essentially impossible to turn it back into an exact copy of the source code it came from. There simply isn't enough information in the machine code to do so.

My second question is that will we read these compiled codes on Arduino ZERO's debug port, which will be a new product for us as developers?

The debug port will work in tandem with appropriate software that will already have access to the source code, so this is not a method for conversion either.

You wont be able to get the code in readable C. It would be in Machine code.

source: Stack Exchange

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

sort: votes


text:
How to display variables on 0.96" OLED with u8glib library?
I have Arduino Uno and 0.96" I2C Oled 4 Pinned display. These are my Arduino codes:
#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);    // VDD=5V SCL=A5 SDA=A4

int a = 10;

void setup(void) {
}

void loop(void) {

  u8g.setFont(u8g_font_gdr25r);
  u8g.drawStr(8, 30, "E");
  u8g.setFont(u8g_font_gdr25r);
  u8g.drawStr(30, 30,"l");
  delay(2000);

  //  u8g.println(a);  //This code raw is not working
  //  delay(2000);
}

I am trying to indicate integer type variable is called "a" to the OLED screen, but u8glib library hasn't got

println( (int) a );

function to do this. I only see

u8g.drawStr();

function that this can't handle integer variables to the display. How can I do that?

The U8glib user reference page mentions a couple of ways to print the value of a number using ASCII characters.
Eg, following the idea at the second mention of sprintf at above link:
char buf[9];
sprintf (buf, "%d", a);
u8g.drawStr(33, 33, buf);

Edit: The above follows the example at the link, but I've struck it out because in general snprintf is safer than sprintf.  See below.
enum {BufSize=9}; // If a is short use a smaller number, eg 5 or 6
char buf[BufSize];
snprintf (buf, BufSize, "%d", a);
u8g.drawStr(33, 33, buf);

The other way is via print.  (Search for U8GLIB::print in above link, and also see arduino.cc's Print docs).
Eg:
u8g.print(a);

To get a newline effect, you may need to have a variable keeping track of the current line number; add 1 to it to get next line's number, and use that as a position parameter in a drawStr call.

Ok, I have found the solution (Thank you @jwpat7) Here is my working code:
#include "U8glib.h"

U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);  // VDD=5V GND=GND SCL=A5 SDA=A4

int a = 0;

void setup() {      }

void loop() {

u8g.firstPage();
 do {
u8g.setFont(u8g_font_gdr25r);
//u8g.drawStr(8, 30, "Eeee");

char buf[9];
sprintf (buf, "%d", a);
u8g.drawStr(18, 3, buf);

  } while( u8g.nextPage() );
  delay(200);
}

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


text:
What's the fastest way to periodically communicate via serial?
I will be using an Arduino as a bridge between a computer high-level Java client and some low-level hardware computing units (e.g. other Arduinos). I need to find a solution to periodically communicate in both ways. It should be possible to send digital, analog inputs to the PC and receive digital, analog outputs from the PC via serial.
I have very specific requirements for my project to work:

Lowest possible latency in both ways. High latency would cause
instability of controlled systems.
Extremely constant, possibly user-defined update period. Varying
sample rate would cause inaccuracies in the control.

I need a very fast solution possible for update frequency of 100 Hz and higher.
So far I have tried to send data via Firmata to my java client using time interrupt.
ISR(TIMER1_COMPA_vect) {
  Firmata.sendAnalog(analog, analogRead(analog));
}

The messages however don't come at a very constant rate and are sometimes held up for twice the sample period or more which is unnaceptable. For higher frequencies this happens even more often. I suspect some kind of a buffer. Do you have any idea where should I look for bottlenecks? Would it be benefiting to design my own communication protocol and ditch Firmata?
EDIT: Look at the attached diagram . Blue lines are "inputs", green lines "outputs". Right now I am trying to design the "Arduino (Bridge)"

You might want to just use millis() and delay to help avoid variance in the sampling rate. For latency, IMHO it'd be better to get a very high baud rate. You could reduce errors with this library here.

I thought using hardware timed interrupt should be significantly more accurate. So nothing in the loop() can slow down the messages. Am I wrong?

You're correct. They would be more accurate, but do remember that, if you want it to always be consistent, you'll have to add a little "padding time" to most code to make sure that something a little longer doesn't hold back the next iteration. It won't make it faster, but it most likely will regulate the time between iterations well. Since I don't know your application, the solution in the first comment was the easiest :)

A USB interface itself may be a poor fit for an application requiring low latency.  It's possible that it would just barely work at the rate you need with very efficient software drivers on both ends, but you should consider the very fact of using USB to itself add a millisecond or more of latency, and your interval is less than 10 ms.  Normally, a control loop should be moved entirely outboard of the USB - ie, use a more capable embedded board ("Arduino" or otherwise) and run the entire control loop on it, passing only non-realtime settings/status over the USB.

I understand your point but it would be impossible for my project. I will be running a simulation of a robot and its enviroment on the PC, therefore I need to communicate periodically with the robot's control unit (to send simulated sensor input, and to receive commands) . This approach is called "hardware in loop" simulation and it's the whole point of my project.

Using hardware timers will be WAY better then one of the arduino constructs like millis(). It'll also be far more deterministic regarding timing constraints.
Of course, if you're including the USB's latency (anywhere from 10-200 mS, unpredictable and uncontrollable), you're probably SOL.

@SagiCZ - then you should host the simulation on a system designed for low-latency I/O, and thus avoid using USB in the critical path.  Many of the ARM-based boards for example can do that, and still run a desktop operating system like linux perhaps letting you move your simulation environment over with a simple recompile.  Alternatively, if you can't come up with low-latency hardware to host a "hardware in the loop" test fixture, perhaps you should drop that approach and run a copy of the robot's program on your PC.

I have come up with the best solution so far, although I have to test it a little more. I will move all the time or latency critical simulation to the Arduino and run the non-critical things on the PC. This way I can take advantage of computers superior processing power and graphics ability and not lose the microsecond precision of microcontrollers. The PC client will also generate and upload a custom Sketch for the "bridge" Arduino each time user changes configuration of the robot.

Lowest possible latency in both ways. High latency would cause instability of controlled systems.

the fact that you are using a not-real-time OS introduce a lot of unpredictable latency, the use of a visrtual machine over that os then add a bit more.
Fast communication can be obtained increasing the baudrate, that will decrease the latency between the sample and the elaboration.
Also sending RAW data instead of string will be faster (no convertion AND less byte send), and finally decreasing the overhead caused by the protocol.
For example Firmata by default use a low baudrate AND will add a lot of overhead to send WHAT kind of operation is doing. Writing your own communication protocol is better.
For example: analogRead use 10bit, so you may send a raw int, 2 byte, 16bit, so 6 bit are lost.. or you can "compress" with a bit of bitwise operation 4 read (40 bit) into 5 byte (40bit, no bit loss) instead of 8(int size * 4)!
AnalogRead is a really slow operation by default on arduino (~200us), but can be faster if you set up a lower prescaler (attention, lower prescaler means less ADC precision. at prescaler 16 guaranteed precision is 8bit, if my memory is good)

Extremely constant, possibly user-defined update period. Varying sample rate would cause inaccuracies in the control.

On the PC side, if you need micro/nano second precision you need a real time os, newest linux kernel add a new special schedule but i think is still hard to find documentation. If less precision is ok, just use a timer.
On the arduino side, using a hardware timer is the best way, see LeOS for a nice scheduler on arduino
Please note HardwareSerial on the arduino side use interrupt to send data, so using it inside an ISR (like you are doing now or with LeOS) is really usafe and deadlock prone.
Also ISR will "slow down" each others, as they cannnot be executed parallel; and analogRead is a realtivly slow operation..
I would use timer to set up a flag, and in the loop if i see the flag, start the analogread, Serial.write and finally Serial.flush (to be sure to not fill Serial buffer, causing a lot of trouble on the arduino reprogrammation reset)

"... but can be faster if you set up a lower prescaler ..." Or if you forgo analogRead() altogether and just have the ADC dump its results into a volatile variable when finished converting and read from that variable upon request.

i dont see how the adc read finished interrupt can help, expecially if not setting the adc. Or are you suggesting to use register insted of snalogread

You set the ADC to autotrigger (off, say, a timer), and have the completion ISR dump the value into the variable. You then read from this variable instead of accessing the ADC directly.

thank you, these are some great ideas.. When it comes to the PC client side I am not going for the RTOS route so I would like to implement the second approach you suggested -> "just use a timer". Could you elaborate on that a little bit? How does timer help me compared to uninterrupted listening to the port? Did you mean I can time the message processing for the cost of being "behind" one or two periods? That would probably be acceptable.

+SagiCZ i was talking about sheduled action. To read the data event or blocking call are optimal solution

What if I schedule the reading to some particular moments in time but the messages come in between those moments?

x arduino and pc: they are bufferized. a ring buffer is used, so when buffer is full, newest reading overwrite oldest

could you be more specific with your question ?
From what I understood:

you have a client java program acting as the "brain" of your system
your control is time sensitive. You have a PID or other regulation loop running on the pc
you have or plan to have multiple arguing boards on your system and you need to communicate with them.
you are dealing with analog IOs

bridging
If you want to stick to serial port,you have to use RS485 or RS422. Those can work as a bus. Protocol on top of that can be Modbus.
Note that this has a higher latency and you need at least 2 serial ports on your bridge
I2C. Lower latency 2 wires bus. Command oriented,runs at 400 kHz. So you have plenty of time to send/receive data
SPI even lower latency as bytes are sent as stream .arduino mega has 5 pins for it. Note that you have to deal with the addressing yourself in this case.
Arduino like many micro controllers is bad as doing many tasks at the same time like for the bridging case. I would avoid using an arduino in this case
latency
As already answered, ADC conversion takes time and you cannot nest interrupt.
Your minimum latency can be computed from the specifications of the arduino.
The maximum latency is a value you fix yourself.
Knowing the amount of time to send one byte on the communication port,
You can decide between options like

run the AD conversion in a loop outside interrupt, put the value inside a variable and do the communication a synchronously inside an interrupt
run the AD conversion interrupt based and the communication in the main loop of operation

conclusions
Don't do hardware in the loop using a PC. The latency and lack of strict timing possibilities worsened by the use of java make it a dead end with your current setup.
Use a stronger micro controller like an AVR32 with USB running the brain of your system.
You can also use a raspberries pi or a beaglebone. Those runs "standard" Linux distributions and so you can use a PC like approach.
In any case guidelines are :

try to stay as close to the micro controller as possible and avoid abstraction libraries and OSes
don't use a pc for hardware in the loop
try to make your task run a synchronously as much as possible
keep your interrupt routines as small as possible

Maybe I could forget about serial but still use Arduino and USB connection. I think there might be a way to set up the connection as a HID device or something entirely different from Serial.
Your conclusion and final suggestions unfortunately dismiss the project's point. Which is to simulate with hardware in the loop but also visualize the simulated robot in java game engine.
I don't think it should be impossible to send the data so fast. I know that for example external audio cards have latency of about 1 ms and send the data with rate of 20 kHz or similar through USB.

I have edited the question with a diagram to help you understand.

I have had great success removing serial from such an example and setting up a closed network and then Ethernet enabling all the arduino devices. I then have a DCHP and SNTP server in the closed network. The PC etc are all in the closed network. I then setup a MQTT server (see www.mosquitto.org) and use the arduino PubSub library on the arduino. I get extremely short round trips with pretty consistent response times and this has the advantage that multiple sources can publish or subscribe to the data steams created. The SNTP server is used so that all the devices get the same time reference to use and I time stamp all messages and can then work out message sequence etc even if they are physically delayed slightly by an Ethernet collision! although in a closed network this is minimized.

This sounds promising. Did you use Arduino ethernet shield? Could you provide more details or point me in a direction to learn about details of this implementation? Ditching serial has been my newest idea :)

@SagiCZ If you are looking for a high-performance PubSub based communication protocol, without the overhead of MQTT broker, you should have a look to my project, it is pretty much that, point-to-point protocol, lightweight C library and a python CLI to communicate with the device, open plots,etc : https://github.com/Overdrivr/pytelemetrycli


text:
RGBW LED strip: which components are required?
I'm brand new to this community, and in electronics as well.
I'm a software developer and I want to start a new journey with a project in mind: I want to control a 5 meters addressable LED strip for my living-room.
I need all the components for this project... I already know eclipse and Java world, but I need help in choosing the components for the project:

which Arduino (starter package maybe?)
LED strip (smd 5050 on sw2812b, sk6812, APA104...) more than 60 LEDs/m
Power Supply for the project

Can you point me to the right direction, posts that can be useful to me, so I can start on good basis?

I doubt that you'd need the starter kit, you only need to pick an Arduino board based on your code storage requirements and power.

NeoPixels
The strips based on the WS2812 / SK6812 and similar chips, known by some as NeoPixels, are clever ways of implementing fully-addressable 24-bit colour LEDs.
One of the clever things is that they only require one data wire, plus power and Gnd, i.e.

+5V
Data
Gnd

The pixel information is sent by precisely timed sequences of 24 bits per pixel. The first pixel "peels off" these 24 bits (ie. 3 x red / green / blue) and then passes the rest on to the next pixel, and so on.
Libraries
Various people have written libraries to do this for you including:

Adafruit library
NeoPixels Revealed: How to (not need to) generate precisely timed signals
My own library which uses SPI

Power
Each pixel draws around 60 mA at maximum brightness (showing white) so you need to allow for a heavy-duty power supply. Particularly if you have 5m of 144 pixels/m then that is 720 pixels, which would require 43.2 amps!
According to Adafruit:

To estimate power supply needs, multiply the number of pixels by 20, then divide the result by 1,000 for the “rule of thumb” power supply rating in Amps.

Even that means you need 14.4 amps for your 720 pixels!
So bear that in mind when sizing your power supply.
Addressing methods
The Adafruit library (as far as I can tell) holds the pixel information in RAM, and then "dumps" it to the NeoPixels in one operation. This lets you do fancy things in memory, and copy the results to the pixels. However that means you need enough RAM for all this. At 3 bytes per pixel (24 bits), if you have 720 pixels, that will be 2160 bytes, which is more RAM than the smaller processors (like the Uno) have.
Larger processors (like the Mega) have more RAM.
An alternative method, as explained here does not keep the data in RAM, but generates the colours "procedurally" on-the-fly. This is much less RAM-intensive, but perhaps less flexible. On that page he links to a YouTube video which shows a humble Arduino Duemilanove (similar to a Uno) driving over 1000 pixels!
Procedural generation however can do quite a lot, for example you can set the entire string to a single colour, change that rapidly, or make a rainbow effect by increasing (say) the red value for each successive pixel. You can also make "chaser" effects quite simply.
The library I wrote is also designed to allow you to use minimal RAM. You could conceivably add in your own storage scheme, perhaps only storing one byte per pixel, with less bits per colour (eg. 2 bits each for red, green, blue) and that would reduce RAM requirements by a third.
Cabling run
You could try sending the data over 2m. I warn you that the timing for a zero-bit is that it has to go HIGH and then LOW within about 400 ns, so you can't afford to have the data signal degrade too much.
When I had a similar string of coloured LEDs set up at Xmas time (not NeoPixels however) I had a long run of a 5V power supply (just using a pair of figure-8 wire), and situated the processor quite close to the pixels. This is probably the safest way of doing it.

Wow that is a well detailed answer, now I'm scared ! joking :) Thanks a lot, i'll keep all of this in mind ! so the strip I found is ok (72/m x 5m = 360 pixel), I'm glad to hear that ^^

BTW I got my 300 NeoPixel string in the mail today. Powering it up with all white at full brightness it consumed 3.9 amps, and even then the end of the strip looked yellow. There is provision on mine for powering both ends, and I guess I would need to do that if I wanted full brightness through the string.

I like the ws2812 RGB LEDs with integrated controller. They can be found on adafruit.com, e.g. here: Adafruit NeoPixel NeoMatrix 8x8.
There are some good tutorials on adafruit.com:

https://learn.adafruit.com/adafruit-neopixel-uberguide/overview
https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices
https://learn.adafruit.com/adafruit-neopixel-uberguide/neomatrix-library

Choosing your Arduino you have to keep in Mind that the Arduino Due runs at 3.3 V, while the Arduino Mega runs at 5 V. The ws2812. But you can use a level shifter to connect an Arduino Due to the ws2812.
Your Arduino is powered via USB, the LED matrices / stripes need their own power supply, but a DC 5V wall plug (something like a cell phone charger) will do the work (check the max. ampere ratings to be high enough for your LEDs).
A starter package depends on what you already have. Some jumper cables are always good to have, basic tools for electronics as well, e.g. a soldering iron or some prototyping board.

thanks a lot for your hints. FYI I'm in France as I heard there was some licence stories about Arduino' name... can I have the Arduino next to me at around 2 meters of the led strip ? or is it better to have a 2 meters long usb cable... ?

Adafruit says to minimize the distance between the LED matrices and the Arduino. but I have seen systems working with ~ 2 m of cable between the Arduino and the LEDs. But a 2 m long USB cable is working as well.

Thanks !! could this strip be ok (model IP30 72Pixel RGB WW) aliexpress ?

You don't need 2m of USB cable. A lot (all?) of Arduinos also have a power input jack. Just extend a 5V power supply to reach it. It will be easier with a 5V Arduino like the Uno. It looks like the strip you mentioned has the same/similar chip (SK6812) to the NeoPixels.

ho now I understand your message ^^ the 2m usb cable was for dialoging with the pc ^^


text:
Arduino 16 MHz with only 3.3V?
Now I have these Arduino Pro Mini from Sparkfun. They are the latest version that I know (yeah, it's the one that have those horrible misaligned pins). Now they are designed around the ATmega328P and have a 16MHz crystal on them.
Now, my question is: Can I run an ATmega328 with a 16MHz crystal while supplying ONLY 3.3V.
The reason I'm doing this is because 5V / 16MHz Pro Minis from China are way cheaper then 3.3 / 8MHz.
Facts that I already know:
If I follow the datasheet to the the letter, this configuration should not work. BUT... After some test, it did work.
Also, I want an answers based on personal experience (NOT OPINIONS) and not datasheet and specs.

[EDIT] Including a way to use the internal clock (at 8MHz) of the ATmega328P would really help!

I doubt anyone here has personal experience testing all the peripherals and instructions of the chips, on hundreds of samples, over the full operating temperature range. That's why, when you care about reliability, you rely on the datasheet. If reliability is not an essential requirement of yours, you already know it works.

The OLIMEXINO-32U4 can be jumpered for 5V or 3.3V and uses 16MHz. The manual has more info about this on page 14.

Set the crystal driver to full-swing and initial prescaler to /8, and then switch to /2 in one of the initialization sections.

Including a way to use the internal clock (at 8MHz) of the ATmega328P would really help! - what does this mean? You want to know how to use the internal clock at 8 MHz, or run it at 16 MHz using the internal clock?

This is not an answer to the questin, more like a solution to the problem (why i comment), but there is lipo stepup modules that gives you 5 volt from a 3.3 battery, enough to run an arduino. Take a look at that.

@Magic-Mouse, thanks but stepping up voltage is not really efficient for me. I'm using a couple of breakouts, all using 3.3V. Stepping up something to then regulate it down is somewhat stupid for my project. Thanks though.

@canadiancyborg the point was not to regulate it down, but you dont have to step up everything. Just the feed to the AT chip.

Which Arduino Type you have used for 16 MHZ and 3.3 V ?

Officially, no.  Practically, often but not always.

If I follow the datasheet to the the letter, this configuration should not work. BUT... After some test, it did work.

The data sheet does not say that it "should not" work, it says that it is that the part is not qualified for operation at 16 MHz below some voltage higher than you want to use.  That does not mean that a given chip cannot work there, it only means that a chip that fails to may not be considered "bad".  Failure may be total and obvious or subtle.
In practice I have seen it work, both on small modified import boards and those with switchable power supply voltage.  But I also recall seeing it fail to work.
Two factors that can make a theoretical difference are part-to-part manufacturing variation and operating temperature.
Note that with an ISP setup you can change the fuses to run the chip on what was sold as a 5v external crystal board, to operate from the internal 8 MHz oscillator instead, and you can do this even while leaving the crystal on the board.  If you also change the brownout detector fuse, you can lower the voltage further, for example to operate without a regulator directly on two AA cells.  Of course that applies to the ATmega itself - any other active components on the board would have to be qualified for the intended voltage too.

According to the datasheet you need 3.78V to run at 16 MHz, and 3.3V isn't that far off. I would be surprised, for example, if it stopped working at 3.77V, because that would mean that the operating at 3.78V was marginal.
I have operated these chips out of spec, for example under voltage, or with a 24 MHz crystal. They seem to work. However I would guess that Atmel's position would be: if you operate out of our specs, don't come crying to us if it is unreliable.
A few percent out of spec will probably work - and 3.3V is 87% of 3.78V. They write those specs to allow for fluctuations in the manufacturing process, and are confident that all their chips would meet them. Probably a lot of chips would be over spec.

Including a way to use the internal clock (at 8MHz) of the ATmega328P would really help!

Set the fuses appropriately. See Engbedded Atmel AVR® Fuse Calculator
For the Atmega328P making the low fuse be 0xE2 should do it.

The reason I'm doing this is because 5V / 16MHz Pro Minis from China are way cheaper then 3.3 / 8MHz.

Be cautious that cheap clone boards may be manufactured with manufacturers' "seconds".

Thanks. Just as a note that the cheap chinese board i have look EXACTLY like originals by sparkfun. all the trademarks are there, and even the oshw logo is there. i doupt they are fake and if they are, well they still did a lot of effort.

A little test, not very scientific, but shows it runs fine on 3.3V - https://www.youtube.com/watch?v=If0eOa0Uj5I.
Again, if you would like to stay withing the specification just use a "clock divider/2" and run your MCU at 8MHz if they have a 16MHz Crystal:
clock_prescale_set(clock_div_2)

http://www.nongnu.org/avr-libc/user-manual/group__avr__power.html

If you set this in software, it requires first booting at 16 MHz.  If you want to use the clock divider this seems like a better proposal, though I can't say I've tried it: http://arduino.stackexchange.com/a/5413/612

Good point, the fuse sets thw clock prescaler to clock_div_8, you can bring it back to clock_div_2 on the first line of your code. Don't forget you'll need the bootloader with the correct speed if you plan to use code upload via usb/serial.

I've built a few 3.3v home-brew-duinos with 16Mhz crystals (because I have a bag of 50 xtals!) - they run fine in the conditions I've put them in so far (on my desk). Some of them may be closer to their margins than others, and might fail at at some otherwise in-spec temperature, for example. If these were intended to go outside (enclosed, of course), I'd have to test them against the conditions they might be subjected to. Or redesign them to keep them in spec in the first-place.
I think the only way to know is to try it on your board and see. I don't have or know of a test-suite for the chip; I've just uploaded known-working sketches to my experimental boards and had no obvious glitches. Yet.

Atmega48/168/328's datasheet graph (under "29.3: Speed Grades") presents maximum safe clock speed for given VDD voltage. It consists of three mathematical functions - 1 constant and 2 linear. I managed to calculate their formulas and sum them up:

where:
x is a VDD voltage [V] and y - max safe clock speed [MHz] you can achieve with the voltage. I've done it, because I've had a need to check, if 3.3V power supply is enought for a 12MHz crystal - and it is (around 13,3MHz max.).

You can use the clock prescaler in conjunction with the CKDIV8 fuse to operate with an 8MHz clock but using a 16MHz crystal.
See the "CLKPR – Clock Prescale Register" details in the data sheet for details (Page 36 in my data sheet 07/2012).
Basically you set the CKDIV8 fuse so the processor runs at 2MHz after power-up. Then once up and running you set the division ratio to 2 which would give 8MHZ operation which is guaranteed at 3.3V.

I am running my atmega328p chip with 3.3 volts because I did not wanted to use a voltage divider when powering the NRF24L01 that is part of my circuit. Because I only have 16mhz crystals and I don't know how to lower the frequency to 8mhz I been running my project with 3.3v and it works great. I been running this code for over a year and I have had no problems.
The code works great even at 2.8v running at 16mhz.  At 2.65v it stops working.

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


text:
i am working on a project smart watch i am getting this error please help
Arduino: 1.6.7 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"
WARNING: Spurious .github folder in 'Adafruit SSD1306' library
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,

                 from sketch\RetroWatchArduino.ino.cpp:1:

bitmap.h:1270: error: expected primary-expression before '__attribute__'

 PROGMEM const unsigned char* const bitmap_array[] = {

 ^

C:\Users\varun\Desktop\retrowatch-master\retrowatch-master\RetroWatch_Arduino\RetroWatchArduino\RetroWatchArduino.ino: In function 'void drawIcon(int, int, int)':

RetroWatchArduino:898: error: 'bitmap_array' was not declared in this scope

   display.drawBitmap(posx, posy, (const unsigned char*)pgm_read_word(&(bitmap_array[icon_num])), 16, 16, WHITE);

                                                                        ^

exit status 1
expected primary-expression before '__attribute__'

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

Information about the smart watch

PROGMEM is in the wrong loctaion. According to the Arduino Website:

Note that because PROGMEM is a variable modifier, there is no hard and fast rule about where it should go, so the Arduino compiler accepts all of the definitions below, which are also synonymous. However experiments have indicPROGMEM ated that, in various versions of Arduino (having to do with GCC version), PROGMEM may work in one location and not in another. The "string table" example below has been tested to work with Arduino 13. Earlier versions of the IDE may work better if PROGMEM is included after the variable name.
const dataType variableName[] PROGMEM = {};   // use this form
const PROGMEM  dataType  variableName[] = {}; // or this form
const dataType PROGMEM variableName[] = {};   // not this one

And I will add to that list:
PROGMEM const dataType variableName[] = {};   // and definitely NOT this one.


text:
Wirelessly communicate between two Arduinos without router
I want to "connect" two Arduinos, without using wires. The range is ~0.2 miles (300 meters). Using Google, I saw too many options.
The idea is to build something like a beacon, so the bandwidth can be small. I want to send 32 or 64 bits/second of data (32 bits for the application + 32 bits for checksum if the module does not guarantee consistency of data).
The communication between Arduinos is bi-directional, and I'm looking for something cheaper than 50 US dollars per module.
Can I use a serial WiFi module for this, without using a router? Do you recommend a 2.4GHz module? Or a RF module?

They are all good possibilities, In order to identify a good choice you have to first define what you want to do. You've answered no useful questions that would narrow the choices besides distance. What  bandwidth? what is your acceptable error rate? what price? bi directional or not? uniquely addressable or not? etc. etc. First define what you want to do then find the right solution

Might want to look into zigbee, they are expensive but tends have a decent range.

I can highly recommend these cheap little 433Mhz radios.  You can get them on amazon, ebay, etc. and they work pretty well for me. Your distances are a bit longer than my situation but I have to go through several walls.

From the picture I see that one (the transmitter ?) seems to have an adjustable coil.
But even if it does, the other (the receiver?) doesn't seem to be adjustable.
Is there some other way to avoid interference from colocated pairs?

However, from the reviews, the max distance for reliable transmission seems to be much less, about 100m.

The type of antenna will have a big impact on range. I've managed 50' with a simple length of wire using the 433 MHz radios. A directional antenna should be able to provide a gain of 5 at least. I considered implementing a CSMA/CD protocol but lost interest at some point. I did implement a Master with multiple Slaves solution. The idea was for a thermostat that could poll slaves with a temp sensor. Each slave had a unique 'address' the master sends a message with the slave's address and a command ('send temp') and waits for a response.

It's a bit unorthodox solution, but have you considered toy walkie-talkies?
They cover the distance you reported, even if some obstacles are in the path and they are relatively cheap, if you go for some sales.
It requires a bit of hacking to connect the arduino to the mic/speaker and the push button, but it shouldn't be too difficult.

My idea isn't use a microphone. Instead, I want to send "digital" data, created by an application, and parse it from the reciever device. ¿There is any way to use the walkie talkies chipset for that?

@Nullpo: there is no such a thing as a digital signal, it's all analog.
It's up to the consumer of the signal to treat it as analog or digital.
In other words: the walkie talkie doesn't care if you transmit voice or a sequence of 1 and 0, as long as the input voltage in within the same range as the voltage provided by the microphone.
And the same goes on the receiving end: the arduino that receives doesn't care that the Walkie talkie thinks it's transmitting voice, as long as the voltage levels are compatible.

To clarify further, what I'm proposing is to remove the microphone and interface directly the Arduino with the board in the walkie talkie.


text:
Can't store RFID data in the next 5 bytes of array
I'm working on RFID project to handle multiple cards.
I did most of the things OK. But now I have one problem. Which is the following:

The RFID code is 5 bytes, so I need an array of 5 bytes. If more cards then the array size = number of card * 5.
For my example I'm working with 2 cards. So array size is 10 bytes.
I can store the first card in the first 5 bytes.

The problem:
I can't store the 2nd card in the next 5 bytes in the array. I don't know why.
This is my only test code:
/****************************** LIBRARIES ******************************/
#include <SPI.h>
#include <RFID.h>

/****************************** DEFINITIONS ******************************/
// pins definitions
#define SS_PIN          10
#define RST_PIN         9

// setup definitions
#define CARDS           2
#define MXCD            CARDS*5

/****************************** VARIABLES ******************************/
// rfid variables:
byte crd_buf[MXCD],card_no;
byte register_lock,check_lock,print_lock;

/****************************** FUNCTIONES ******************************/
// rfid functions
void register_accepted_card(void);
void record_new_cards(void);
void check_card(void);
void print_registered_cards(void);

// objects
RFID rfid(SS_PIN, RST_PIN);

//////////////////////////////////////////////////////////////////////
void setup(){
  Serial.begin(9600);
  SPI.begin();
  rfid.init();
}

void loop(){
    register_accepted_card(); // apply only once
}

void register_accepted_card(void){
  if (!register_lock) {
    if (rfid.isCard()) {
      if(rfid.readCardSerial()){
        if(card_no>0){
          for(byte i = 0; i<card_no; i++){
            if(!memcmp((crd_buf+(i*5)),rfid.serNum,5)){

              Serial.println("already card is");
              for(byte p = i*5; p<(i*5)+5; p++){
                Serial.print(crd_buf[p],HEX);Serial.print(", ");}
                Serial.println();

              lcd_state = ALREADY_MSG;
              register_lock = 1;
            }
          }
        }

        //////////////////////////
        // problem is in this part
        //////////////////////////

        if(!register_lock){

          for(byte i=card_no*5;i<(card_no*5)+5;i++){
            crd_buf[i] = rfid.serNum[i];}

          Serial.print("loop#"); Serial.println(card_no);
          Serial.print("start index ");Serial.println(card_no*5);
          Serial.print("end index ");Serial.println((card_no*5)+5);
          Serial.println();

          Serial.print("card#"); Serial.println(card_no+1);
          for(byte i=card_no*5;i<(card_no*5)+5;i++){
            Serial.print(crd_buf[i],HEX);Serial.print(", ");}
          Serial.println();Serial.println("//////////////////////////");

          card_no++;
          if(card_no >= CARDS){lcd_state = FINISH_MSG;}
          else{lcd_state = REGISTER_MSG;}
          register_lock = 1;
        }
      }
    }
    rfid.halt();
  }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
My second question, for the part of checking the cards after finishing registering the cards to be accepted.
I did a for loop for the number of cards to get the card that is registered in the array and send a message that the card is stored and accepted, otherwise, it returns a denied message that the card isn't stored in the array with alarm buzzer.
The problem that is the for loop checks the card for all the indexes in the array which is what I want but the result is mixed with accepted and denied.
The question is how to get out of the for loop?
void check_card(void){
  if (check_lock){
    if (rfid.isCard()){
      if (rfid.readCardSerial()){
        for(byte i=0;i<card_no;i++){

          // start of for loop
          Serial.print("check# ");Serial.println(i);
          if(!memcmp(crd_buf+(i*5),rfid.serNum,5)){
            Serial.println("card accepted");
            digitalWrite(ACCEPT_LED,HIGH);
            digitalWrite(DENIED_LED,LOW);
            digitalWrite(BUZZER,LOW);
            check_lock = 0;
            sys_state = 1;
            lcd_state = ACCEPTED_MSG;
          }
          else{
            Serial.println("card denied");
            digitalWrite(ACCEPT_LED,LOW);
            digitalWrite(DENIED_LED,HIGH);
            digitalWrite(BUZZER,HIGH);
            check_lock = 0;
            sys_state = 1;
            lcd_state = DENIED_MSG;
          }
        }
            // end of for loop

      }
      rfid.halt();
    }
  }
}

Why not a 2D array of crd_buf[CARDS][5];? So much simpler to deal with.

OK, I should try your method. But I'm really confused of why it's not working as I tested it in codeblocks and it is working fine ! Is there something I don't know about Arduino compiler ? Is it possible that the compiler is not defined to handle these operations on arrays ? to me, I just don't think so, Arduino compiler is really professional. Maybe I'm doing something wrong .. But I should try the 2D version, thanks dude :)

Your problem is this bit:
      for(byte i=card_no*5;i<(card_no*5)+5;i++){
        crd_buf[i] = rfid.serNum[i];}

For the first card you're copying bytes 0-4 of the serNum to bytes 0-4 of crd_buf.
However for the second card you're copying bytes 5-9 of serNum to bytes 5-9 of crd_buf.  That's correct for crd_buf but wrong for serNum.
The right way would be to add card_no*5 to i when creating the index:
      for(byte i=0; i<5; i++){
        crd_buf[(card_no*5) + i] = rfid.serNum[i];}

Or better to define your card buffer as a 2D array so you don't need to do that calculation:
byte crd_buf[CARDS][5];

for (i = 0; i < 5; i++) {
    crd_buf[card_no][i] = rfid.serNum[i];
}

Or simpler:
memcpy(crd_buf[card_no], rfid.serNum, 5);

For your second question, don't print your message at all in the loop.
Instead start out assuming that access is denied. Then if a card matches, grant access.  The simplest way is with a flag.
if (rfid.readCardSerial()){

    bool accessGranted = false;  // A flag to store the state - start off denied.

    for(byte i=0;i<card_no;i++){
        if(!memcmp(crd_buf+(i*5),rfid.serNum,5)){
            accessGranted = true;
        }
    }

    // replace these with your own message routines.
    if (accessGranted) {
        Serial.println("Access Granted");
    } else {
        Serial.println("Access Denied");
    }
}

Comments are not for extended discussion; this conversation has been moved to chat.

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


text:
Why it's not possible to manipulate the TWSR directly?
I think I forgot the reason for this SFR manipulation in microcontrollers; like, checking the TWSR in twi.
The technique for checking the values of the TWSR is by masking it with another variable or a value.
So, why not checking the TWSR directly in; for example, switch function for checking the values of TWSR?
Like, switch (TWSR)
instead of
uint8_t Status;
  Status = TWSR & 0xF8;
  switch(Status)
Or, substitute it in any function; like, Serial.println(TWSR); or digitalRead(TWSR);. DO I have to mask it? If so then why?

bit 0 and bit 1 of the TWSR register specify the I2C clock speed, so they may differ depending on the speed you selected (Wire.setClock())

What I mean is that why I have to mask TWSR instead of substitute it in any function parameter?

You mask it to ignore bits you don't care about.  In a switch, you'd have to list all of those as explicit cases which would be inefficient to express in  source code, even if a very optimizing compiler might figure out how to condense the actual tests to ignore the irrelevant bits.

OK, then why don't just check for TWSR values even with bit 0 and bit 1 included in the test, because they have ..... or wait. I'm sorry, it must be masked because these two bits may change between different I2C clock speeds.

Why it's not possible to manipulate the TWSR directly?
  i2c c switch

Because your premise is wrong: it is routinely done to manipulate twsr directly.
As to the use of masks, well, because sometimes you only care about certain bits but not others. So you mask away those that you don't want.
Just that simple.

OK, so all SFRs are accessible for direct manipulation. But this one is masked for unwanted bits. Thank you :)

The mask is a must, because bit 0 and bit 1 are I2C clock speed bits and they are changeable between different I2C clock speed configurations.


text:
How to stop sending the last received char of UART echo function?
I developed a code for uart based ISR with linear buffers, the problem is that it keep sending the last received char in Arduino IDE.
Here's the application code:
#include "uart_new.h"

void setup() {
uart_init_new(103);
DDRB = 0xff;
}

void loop() {
uint16_t c;
c = get_char();
if (c & NO_DATA)
{
  PORTB |= (1<<PB5);
  _delay_ms(500);
  PORTB &= ~(1<<PB5);
  _delay_ms(500);
}
else
{
  put_char(c);
}
}

The header file:
#ifndef uart_new_H_
#define uart_new_H_

#define NO_DATA     0x0100
#define Buf_OF      0x0200
#define FR_Er       0x0400
#define DOR_Er      0x0800
#define PARTY_Er    0x1000

#define buf_s 32
#define buf_mask Buf_s - 1
#define baud_rate 9600

void uart_init_new(uint16_t ubrr);
void put_char(uint8_t data);
uint16_t get_char(void);
void put_s(uint8_t *str);

#endif // uart_new_H_

The source code:
#include <avr/io.h>
#include <Arduino.h>
#include "uart_new.h"

/*******************************************
If you want to prevent reading a string
backwards then you need FIFO implementation
*******************************************/

static volatile uint8_t rx_buf[32],tx_buf[32];
static volatile uint8_t rx_p,tx_p,rx_cnt,tx_cnt;
static volatile uint8_t rx_errors,tx_sBuf,rx_sBuf;

void uart_init_new(uint16_t ubrr)
{
    rx_p=0,tx_p=0,rx_cnt=0,tx_cnt=0;
    UBRR0H = (uint8_t)(ubrr>>8);
    UBRR0L = (uint8_t)ubrr;
    UCSR0B = (1<<RXEN0)|(1<<TXEN0)|(1<<RXCIE0); //Enable Rx and Tx & Receive interrupt
    UCSR0C = (1<<USBS0)|(3<<UCSZ00);            //Set frame format: 8data, 2stop bit
}

uint16_t get_char(void)
{
    if (rx_cnt == 0)
        return NO_DATA;
    else if (rx_p < rx_cnt)
        return rx_buf[rx_p++];
}

void put_char(uint8_t data)
{
    if (tx_cnt < 32)                        // start count the input data
        tx_buf[tx_cnt++] = data;            // 1st input location tx_cnt

        UCSR0B |= (1<<UDRIE0);
}

void put_s(uint8_t *str)
{
    while (*str)
        put_char(*str++);
}

ISR(USART_RX_vect)
{
    if (rx_cnt < 32)                        // start count the received data
        rx_buf[rx_cnt++]=UDR0;              // 1st output location rx_cnt
    else
        rx_cnt = 0;                         // when the counter reached max value, reset it, overwrite everything

if (!(UCSR0A & (1<<RXC0)))
        UCSR0B &= ~(1<<UDRIE0);
}
ISR(USART_UDRE_vect)
{
    uint8_t i;
    if (tx_p < tx_cnt)                      // check if pointer < counted data
        UDR0 = tx_buf[tx_p++];
        else
        {
            for (i=0;i<tx_cnt;i++)
                tx_buf[i]=0;
            tx_p = 0;                       // when the pointer reach max value, reset it
            tx_cnt= 0;                      // also reset counter for new transmission
            UCSR0B &= ~(1<<UDRIE0);         // disable empty data register interrupt
        }
}

If the there's a received char, then ISR is executed, the function exit the LED blink loop, but when the receive stops and there're no more data it doesn't return the blink state and keeps sending the last received char. How to solve this problem?

We cannot see the code inside your UART functions. You have to show us. Also: are you sure, that the buffer is emptied correctly? It seems as the last byte is not deleted after the read, hence getting read over and over again

Post updated, added the main source code.

How is the NO_DATA const defined?  Are you sure, that you have to use the bitwise & in the if statement? Shouldn't you check for equality with ==? Please also include the corresponding header file

The Arduino core library provides the Serial object, which is a perfectly good driver for the UART. Why would you want to replace it with your broken implementation? 2. If you really want to reimplement it, start by learning how a ring buffer works.

Well, I want to learn how to program microcontroller peripherals so I get more skills in programming, if I'm having problems now then it means I'm still at a low level in programming. I know Serial and I know other ready pre-written codes but I have to be good at programming core peripherals so I'm good to go with larger projects.

Post updated with header file.

There are many, many problems with this code. The most fundamental flaw
is that it uses linear buffers, where you should be using circular
buffers instead. I'll come to this later. Now, if we look
at the details, in the header file:
#define Buf_OF      0x0200

This, and a few other macros, serve no purpose. Do not put "TODO" items
in the code: put them in a TODO file, or as comments. Strive to always
have your code in a clean state. More so when you post it in a public
place.
#define buf_mask Buf_s - 1

This is presumably intended to be used as a bit mask, but it will not
work reliably. For example, if you try to complement the mask as
~buf_mask, the preprocessor will expand that to ~Buf_s - 1, and the
compiler will interpret it as (~Buf_s) - 1, which is not what you
want. You should always parenthesize any expression you use in a macro,
as
#define buf_mask (Buf_s - 1)

Later,
void put_s(uint8_t *str);

If you want to be able to issue calls like put_s("Hello!");, then you
should declare the function as:
void put_s(const char *str);

Now, in the implementation, you have:
static volatile uint8_t rx_errors,tx_sBuf,rx_sBuf;

All those are unused. Remove them. Again, this is supposed to be a
program, not a TODO list.
Later,
uint16_t get_char(void)
{
    if (rx_cnt == 0)
        return NO_DATA;
    else if (rx_p < rx_cnt)
        return rx_buf[rx_p++];
}

The compiler should have warned you about this: what if both conditions
are false? In this case the function will return by reaching its end,
with no specified return value. This is undefined behavior. You should
probably return NO_DATA in this case. But then, that's what you should
return every time you are not returning valid data, so the function can
be simply written as:
uint16_t get_char(void)
{
    if (rx_p < rx_cnt)
        return rx_buf[rx_p++];
    else
        return NO_DATA;
}

Later, in ISR(USART_RX_vect),
if (rx_cnt < 32)
    rx_buf[rx_cnt++]=UDR0;
else
    rx_cnt = 0;

If you set rx_cnt to zero without updating rx_p, then the subsequent
characters that you will put in the buffer will be ignored by
get_char() until you fill the buffer up to rx_p. Thus you presumably
want to set rx_p to zero also. And if you do this at the start if the
ISR, you ensure that at least the current character is not lost:
// when the counter reached max value, reset the buffer
if (rx_cnt >= 32) {
    rx_p = 0;
    rx_cnt = 0;
}
rx_buf[rx_cnt++]=UDR0;

Further in the ISR:
if (!(UCSR0A & (1<<RXC0)))
    UCSR0B &= ~(1<<UDRIE0);

This makes no sense: if you have no pending character in the receive
register (which you should not have, as you have just read that
register), then you disable the ISR that serves the transmitter. The
transmitter and the receiver should be able to work independently:
remove those lines.
Then, in ISR(USART_UDRE_vect):
for (i=0;i<tx_cnt;i++)
    tx_buf[i]=0;

This serves no purpose. If you handle your buffers properly, you should
never access uninitialized data in them. Thus you will never read the
zeroes you are writing here. Again, remove those lines.
If you implement all the fixes above, you should end up with a code that
“kind of” works. There are still a couple of issues though:
Race conditions
If get_char() gets interrupted by ISR(USART_RX_vect), you can get
what is known as a “race condition”, which can lead to incoherent
behavior or data corruption. For example, testing rx_p<rx_cnt is not
atomic: the CPU has to read rx_cnt from RAM, then read rx_p, then
compare them. If the interrupt fires between the two memory reads, the
ISR can set both values to zero, then the test will compare the old
rx_cnt with the new rx_p (which is now zero) and incorrectly assume
there is valid data to be returned.
There are other places where this can byte you. For example, rx_p++ is
not atomic either, it's a read-modify-write sequence that can very well
be interrupted in the middle. And there are similar issues if
put_char() gets interrupted by ISR(USART_UDRE_vect).
The fix for these issues is to disable interrupts while you are in the
“critical sections” that access data shared with the ISRs. This can be
done using noInterrupts()/interrupts() pairs or, if you prefer the
avr-libc style, with atomically executed code blocks. For
example:
#include <util/atomic.h>

uint16_t get_char(void)
{
    uint16_t result = NO_DATA;
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
        if (rx_p < rx_cnt)
            result = rx_buf[rx_p++];
    }
    return result;
}

A similar protection is needed in put_char().
Linear buffers
This is the main flaw, because it will require you to rethink a
significant part of your code. Imagine what can happen if the UART
transmitter lags slightly behind your program calling put_char(). Say
you reach tx_p = 30 and tx_cnt = 32. Then your
buffer has 30 “empty” cells (from 0 to 29 the space is available, as
that data has already been sent) and two cells with bytes pending to be
sent (at positions 30 and 31). If you call now put_char() to send an
extra byte, that byte will be lost (because tx_cnt<32 is false). This
is unacceptable: you should not loose data when the buffer is almost
empty!
The solution is to put the extra byte at position 0, the next one at
position 1, etc. But this creates a complication: now the pending bytes
are at positions 30, 31, 0, 1... At this point your buffer becomes a
circular buffer. It's not a big deal, but you must
read about the subject before you try to implement it.
Note that the same issue applies to the receive buffer: both buffers
should be made circular.

Thank you very much for the explanations and declaring my mistakes, now I'm trying to improve the code with linear buffers until I get the code to work with very minimal errors, then I move to circular buffers. My question is that can linear buffers be very efficient as circular buffers?

Again, thank you very much, I actually tweaked the code little more this morning. I would like you to provide me with your opinion. But where should I post the new code?

Also, I want you to know that I want to do more testing on uart and I want to test my skills in C and how I can solve problems. I know that circular buffers are the best option for uart, but even so I'm trying to do the best code with linear buffers, then I move to circular buffers.


text:
A word after function arguments braces
I'm just reading through a header files for task code in ESP8266 SDK.
I found this line and wondering what does the word PRIVILEGED_FUNCTION after the function arguments braces means ?
void vTaskDelay( const TickType_t xTicksToDelay ) PRIVILEGED_FUNCTION;

PRIVILEGED_FUNCTION is defined here, but why it's used after the function braces ?
/* Ensure API functions go in the privileged execution section. */
#define PRIVILEGED_FUNCTION __attribute__((section("privileged_functions")))
#define PRIVILEGED_DATA __attribute__((section("privileged_data")))

That's impossible to tell without looking in the source code for that SDK.
However it will just be a pre-processor macro which probably expands out to one or more attributes, some of which may be specific to the XTensa LX106 compiler.

Update after your edit:
It places the function in the privileged_function section. That section is then placed into a specific area of memory by the linker.
To further examine what it does you will have to look in the linker script to see how it handles that section, and what that means from the chip's perspective, by cross-referencing that with the chip's technical datasheet.

OK, let me check where that word is defined.

I edited the post.

Yep, you're right #include <xtensa/config/core.h> #include <xtensa/tie/xt_interrupt.h> #include <xtensa/tie/xt_timer.h> it's xtensa.

Replay to your answer: Thanks for the explanation. But my question also is about the method of putting something after function braces in C programming rules. What does that method called ?

It’s called writing code.

It's called adding attributes to a function prototype. They can go anywhere in the prototype.

@Majenko .. dude, thank you so much. I just feel honored that you reply to me. Thanks again !

So, it can be also like this: void vTaskDelay PRIVILEGED_FUNCTION( const TickType_t xTicksToDelay ); ? That I can add this attribute, before after the name of the function or even after the braces of function parameters, right ?

@R1S8K yep, that's right.


text:
Arduino nano & pro micro SPI simple communication
I'm working with Arduino boards with AVR C coding to perform simple SPI communication from master for simple blink application on slave side.
They don't work, the TX function on the master side doesn't seem to work, after serial monitor debugging is discovered the function never get over the while loop! Why is that?
Here are the codes I worked on last night:
Master:
/* nano board is the Master and transmit
  data to slave to blink LEDs */

void SPI_Init(void);
void SPI_TX(uint8_t data);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//start Serial
  Serial.println("Setting Up");
  void SPI_Init();
  delay(100);
  Serial.println("SPI intialization is complete");
}

void loop() {
  uint8_t d = 0x20;
  SPI_TX(d);
  Serial.println("just sent the 1st byte");
  _delay_ms(400);
  d = 01;
  SPI_TX(d);
  Serial.println("just sent the 2nd byte");
  _delay_ms(400);
}

void SPI_Init(void)
{
  DDRB = (1 << DDB3) | (1 << DDB1); // DDB2 MOSI, DDB1 SCK
  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0);
}

void SPI_TX(uint8_t data)
{
  SPDR = data;
  while (!(SPSR & (1 << SPIF)));
}

-------------------------------------------------------------- -

Slave:
-------------------------------------------------------------- -

/* pro micro as slave and receives data then push them on
  PORTD and PORTB to blink LEDs */

void SPI_Init_S(void);
void SPI_RX(void);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//start Serial
  Serial.println("Setting Up");
  SPI_Init_S();
  delay(100);
  Serial.println("SPI intialization is complete");
  DDRD = (1 << DDD5); // TX LED as output
  DDRB = (1 << DDB0); // RX LED as output
}

void loop() {
  // put your main code here, to run repeatedly:
  SPI_RX();
  PORTD = SPDR;   // blink the TX LED on pro micro board
  _delay_ms(500);
  SPI_RX();
  PORTB = SPDR;   // blink the RX LED on pro micro board
  _delay_ms(500);
}

void SPI_Init_S(void)
{
  SPCR = (1 << SPE) | (1 << SPR0);
}

void SPI_RX(void)
{
  return SPDR;
}

 void setup() {
// put your setup code here, to run once:
 Serial.begin(9600);//start Serial
 Serial.println("Setting Up");
 void SPI_Init(void);   // <---------------- this is wrong!
 delay(100);
 Serial.println("SPI intialization is complete");
 }

That isn't how you call a function.
It should read:
SPI_Init ();

You should use SS (Select Slave) pin for synchronization on both devices. If you have master with default settings for SS pin (= INPUT), any interferences will switch your master into the slave mode and SPI_TX will wait forever for clock pulses from outside.
Without using SS on both sides it can be also shifted (unsynchronized).
Edit: And yes, also not calling SPI_Init causes pretty similar deadlock.

Where is the SS pin on the pro micro board? I couldn't find it! So I switched the configuration to Uno master and Nano slave and it's still not working! Why? the master TX function is not passing and not executing the next commands!


text:
Can the official arduino GSM shield library be changed to work with hardware serial on mega
I have a complex requirement that uses a number of libraries that depend on timing I.e. OneWire. When using the official GSM shield on a mega, it loads a version of software serial to talk to the GSM. I want to make it use a spare hardware serial port on the MEGA for more timing stability. How should I modify the GSM library to (optionally) auto detect a MEGA and then use a nominated serial port. I am happy to jumper the correct pins from the mega serial hardware port to the bent outwards pins 2 and 3 of the GSM shield ( pin 2 is already bent out if you use a MEGA anyway).

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ........

Thanks this will work but I need the help to change the libraries from using the customized soft serial code and allow me to select a hardware serial pin...this is the real issue.

AltSoftSerial might help you in this case...

Do you absolutely need to use serial0?

I don't think AltSoftSerial is going to help as the goal seems to be to use one of the additional available hardware serial ports.  Presumably going through the library and changing the soft serial references to the alternate hardware serial object would do it (or putting the selection inside ifdef's as jippie proposed).

Did somebody managed to do this?

Before we start, note that it might not be the right pinout for the GSM shield to use a hardware serial port on the Mega. Beware of some nasty wiring.
Poking around on Github, I found this is the directory for the GSM library. Ladies and gentlemen, it's time to break something important get our hands dirty! Draw your  chairs close for a tale of touching code you shouldn't touch!
Click on the src folder to open it up. When I first opened this up, I was somewhat scared by the number of files. However, I had a plan:

Find the name of the SoftwareSerial instance. I'm guessing that they would use only one object to do this to prevent redundancy. In addition, I'm going to guess that most serial data is handles though a single file, but I'll have to confirm this.
Remove instances of the SoftwareSerial Object.
Clean up any remaining issues with the "port"

After more poking around, I noticed that the library actually uses a unique version of the SoftwareSerial library, so it will be even harder to do this. Yay us! On the upside, we know exactly what code to replace. Fasten your seatbelts, this is about to get pretty nasty.
Okay, take a step back here and figure out what we want to modify. First of all, it's a terrible idea to modify the libraries directly in the directory that the Arduino IDE uses.
So, if you were to make a copy from the src folder for the GSM library into the Arduino "libraries" folder, it wouldn't be enough. The Arduino IDE would get confused when there would be two identical header files to use. You will need to rename the main header file and use just that one instead to include into your projects. In addition, most of the files in the library probably reference that file, so make sure to rename any references within the library to that one file. A quick CTRL + SHIFT + F on the Atom text editor will search the entire project I'm working on. I'm not entirely sure if a folder name would mess up the Arduino IDE, but it'd be a good idea to rename the folder to whatever your library is called, at least for readability purposes.
Before we continue, let's make sure that the library still compiles without us playing with the code. Import the new library into a basic GSM example sketch and see if it compiles and works normally.
It compiles? Great. Let's go on!
The file that does serial is the GSM3SoftSerial.cpp file. Without actually porting it, I can't give you a ton of advice here. Look through and see when variables are created, used, and modified. If you're not sure, I'm in chat sometimes: feel free to ask there on minor questions and ping me with @AnnonomusPenguin or leave a comment on this post.
I'd also advise to leave everything in there that you're not sure of, make sure it works with hardware serial, and line by line start removing that variable and see if anything breaks. A great too for this would be to use a tool like Git/Github (or other version control software) to help you revert changes that broke something or to see, overall, what you've changed.
So, after replacing the code inside the functions (finalWrite, the ISRs, and the begin/clear seem like the ones you should touch), compile the code and see if it works!


text:
Larger NFC antenna?
Goal: I would like to be able to transfer some information to an Arduino Uno board via an NFC shield/antenna. The situation requires that the NFC tag may potentially hit anywhere within a circular area about a 12 inches in diameter.
Is it possible to increase the size of an NFC antenna? Possibly creating a loop antenna whereby the tag could be read from anywhere inside the loop.
I was thinking maybe if that isn't possible, it might be better to create an antenna array spanning the size of the area needed. Though I may have problems with overlap or double reads this way.
Has anyone attempted this before?
Note: I am not worried about increasing the z distance from the plane, just the x/y range. In fact, I still want the z distance to be very short as to not interfere with other antennas nearby.

http://en.wikipedia.org/wiki/Hilbert_curve

Welcome to Arduino.SE, aowie1! I'm a reviewer on this site, and we deal with Arduino questions here, so I'm wondering how your question relates to Arduinos. Maybe you could edit your question to tell us how Arduinos relate to your setup, or maybe we should just migrate your question to a more appropriate site (I'm thinking EE.SE, but I'm not sure it's on-topic there either).

In general the size and geometry of the antenna is directly related to the carrier frequency. The antenna is tuned to the output signal of the transmitter/receiver. If you change an optimized antenna, it is no longer optimized and its performance will drop. So you can't keep extending an antenna, trying to improve its range.
The important question to be asked is if the existing antenna is already optimally sized for the transmitter/receiver. With these small things transmitter/receiver and antenna are usually closely matched. Even if the antenna is smaller than expected by math, the transmitter/receiver connected to it may be compensated for that.
With a receiver or a low* power transmitter, there is no harm in testing another antenna, but you'll probably won't improve performance much.

*) Notice that a high power transmitter can blow its output stage when connected to an unmatched load/antenna, but that is unlikely with NFC.

While you can't simply change the size of an antenna, it is generally possible to design a physically larger antenna which has a greater range, either by intercepting more field energy or by being more directional - but this requires a real understanding of how an antenna works.  It may also be possible to combine an array of several somewhat independent sub-antennas in order to have one of them be in the near field of a greater volume of potential transmitter positions.


text:
do i need to also connect GND and 3.3v
I am trying to run this code:
https://github.com/miguelbalboa/rfid/blob/master/examples/ReadNUID/ReadNUID.ino
Using an ESP8266 based D1 board and an RFID-RC522.
I am not able to get it to detect the rfid tags ...
the serial monitor just shows:
 ets Jan  8 2013,rst cause:4, boot mode:(3,4)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld

The "Typical pin layout used" section of the above document does not mention any connections on the 3.3V & GND pins of the RFID-RC522 card.
Does this mean that I do not need to connect them?
Or is is just so obvious that I should connect them that they did not bother to write it in that section?

Where is this "written down" that you are talking about?

in the  "Typical pin layout" section of the document I mentioned above.

Stupid question, but apart from connecting the power, have you uploaded the code?

It is just so obvious that you should connect them that they did not bother to write it down.
The reader needs power. That is taken as read. Without power it can do nothing. Why would they bother to waste time telling you to connect the things that you have to connect regardless? The only things that they tell you to connect are things that are specific to the sketch - i.e., which IO pins to connect to which function on the reader. Power doesn't change - it's the same from sketch to sketch and from person to person. The IO pins do, though, and need to be detailed. Power and ground don't.

o.k. thanks. Its the first time I try to connect anything to my arduino... wat about an IRQ pin on the RC522? is this another standard pin I should know about? or does it just remain un connected?

@epeleg You said you were using a D1.

Sorry, your are right of course.It is indeed a D1 board. being new to this area I still think of all those boards as "arduinos" but I now start to understand that this is not the case and each board is different. So to be more precise I am using a an ESP8266 based D1. and I think its considered a "retired" board as it turns out that there are newer releases of it (R2).
That said, I do own also an "adeept" uno - is this considered an arduino? or arduino compatible board?

Even after connecting the 3.3V and GND wires I still cant get the RFID-RC522 to detect neither the plastic nor pvc tag. I wander if I will have better luck if I use the "adeept" Uno... because I realy don't know why it does not work... maybe i need to initialize the tags somehow?

just to add - I do manage to send a program to the D1 board and for example blink its onboard led.


text:
How fast can I drive a stepper motor?
I have a 28BYJ 48, 5V stepper motor. After some trial and error I got it working with the all the sample examples in Arduino IDE.
However when I increase the speed of the motor using setSpeed() beyond 15, the motor stopped rotating. Following is the configuration in which I am running the motor.
const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
myStepper.setSpeed(15);

I wanted to understand what factors limit the speed. And how fast can I rotate this motor?
Thanks,
Manish

Read about chopping drivers.  There are many answered questions on EESE, no need for a new one.

"I wanted to understand what factors limit the speed. And how fast can I rotate this motor?"
Read through the data sheet for your motor-the answers are there. Each different motor has its own data sheet. This will require some work on your part to find the data sheet and the info from it you require. Which can be used to deduce the answer your question.

While the data sheet will give you the inductance the actual speed limitation of a given motor is determined not by the motor but by the driver's available voltage, which must be many times the nominal motor voltage.  Often all you really need to know about the motor is rated current, or steady state voltage from which it can be calculated.

@ChrisStratton yeah-youre right- it would depend on the circuit controlling the motor too. So youre's sayin the speed limitation does not strongly depend on the information in the data sheet. .

The inductance may the used as a parameter to a chopping software-if the motor is chopping driven


text:
Connecting esp8266 using Arduino
I am trying to connect to esp8266 using Arduino UNO. There are various things on the internet having mixed information and hence I am seeking some clarity.
I followed these instructions, but could not get to connect to ESP8266 using AT command. http://cordobo.com/2300-flash-esp8266-01-with-arduino-uno/
I have following questions:

Can I connect ESP8266 directly to Tx/Rx without voltage divider or level shifter? I also suspect that the voltage divider connections are wrong. As per my understanding, the Tx from Arduino should be divided, and the divider output should be connected to ESP8266.
When I connected the shield as described, the shield gets hot. Is there any way to conclude if the shield is damaged or not?
When I connect the device using voltage divider the blue LED on the shield also lights up. Without divider, it does not light up. What is the significance of the blue LED?

Hardware
ESP8266-01 pinout

Circuit using voltage divider

Circuit without voltage divider

I tried both the methods. The one without voltage divider (section 3.2) and the one with voltage divider (Section 3.1). I could not get the AT commands work with either method. When I connect using voltage divider the blue LED was turned on. When connecting without voltage divider the blue LED did not light.

There are a number of issues with the tutorial you've listed there.
Firstly, a voltage divider is very highly recommended as the ESP8266 cannot handle more than 3.3V, however, the connections for the voltage divider in the tutorial you linked to are the wrong way round (as you suspected).
Secondly, you cannot power the ESP8266 directly from the Arduino, as the power requirements are higher than the Arduino's on board 3.3V regulator. A separate power supply or regulator is recommended. This might be cause of it getting hot (the onboard regulator maybe - but I can't be sure as there is not enough information from your initial post as to exactly what is getting hot).
There are 2 LED's on the ESP8266 shield (the one used in the tutorial you've linked to) one is power and the blue one is wifi communication.
The other potential issue with the tutorial you've linked to is that they have used Arduino pins 0 and 1 to connect to the ESP8266 - while this will work, the problem is that the Arduino uses pins 0 and 1 to communicate over USB with a computer, which means that in in that configuration you cannot use Serial monitor to send/receive data.

Thanks for the confirmation about the voltage divider. I did try with Arduino 3.3V output and surprisingly it was shiled that was getting hot and not Arduino.

If you don't use Arduino 0 and 1 then you can use SoftwareSerial, but that can not support high data rates.  9600 is usually OK, I don't know about higher.

Arduino Tx — resistor (1/3) — tap to ESP-01 Rx — resistor (2/3) – GND

@holmez Do I need to do same for Rx pin well?

@ManishSapariya You only need to do it for the Arduino Tx, because you're changing the transmission voltage from 5V to 3.3V. The ESP8266 will transmit at 3.3V, which the Arduino is happy with.

Some ESP boards are 5v tolerant on the digital pins, some aren't. So it depends on what board you have, I don't think the one in the tutorial is.
If you are using serial to communicate the a resistor divider will not work.  You need a proper level shifter, which you should be able to get for less than a $1.  Remember you will probably need to down shift the Tx from the Arduino and Up Shift the RX to the Arduino.

A resistor divider will work as long as the resistors are low enough, but not too low, resistance. I found 1K + 2K worked, but 10K + 20K didn't.

what do you mean by "some are, some aren't" 5v tolerant? Which ones are which? where did you find such information?

@dandavis - The ESP8266 chip data sheet says that the GPIO pins only accept 3.3v max (http://download.arduino.org/products/UNOWIFI/0A-ESP8266-Datasheet-EN-v4.3.pdf), but I know the Node Lua and Wemos D1 are 5v tolerant (well they didn't burn).  I don't have a definitive list, in fact I would even stake a donut on the fact that all Wemos D1s are 5v tolerant, because there are so many different designs of the "same thing"

looking at the D1's schematic,  the GPIOs are almost all wired straight-through to the 12F module, which would imply all 12Fs share the property. I believe it comes down to quality/die luck: the only one (of dozens) i've had that was noticeably finicky w/ 5v components was one that also froze when "overclocked" to 160. The main issues likely stem from too much heat, and a D1 probably dissipates heat better than an ESP01, commanding more volume in an enclosure if nothing else...

I agree, I suspect they should all be 3.3, but sometimes you get away with it :)

I'm working with ESP-12S which use ESP8266 recently.
My main goal is to use UART-WIFI passthrough mode, so I only need VCC, RX, TX, GND.
These are the steps I take:

Use USB to TTL converter to link WIFI module to PC for WIFI configuration. (two USB converter were used for power issue)

On PC I used minicom to open the USB serial. Use AT commands(espressif.com/sites/default/files/documentation/4a-esp8266_at_instruction_set_en.pdf) to config WIFI module:
AT+RESTORE              // restores the factory default settings
AT+GMR                  // checks version information
AT+RST                  // restarts the module
AT+CWMODE_DEF=1         // set station mode
AT+CWJAP_DEF="APname","password"    // connect to AP
AT+CWDHCP_DEF=1,1       // set station mode with DHCP
AT+CWAUTOCONN=1         // auto connect
AT+CIFSR                // show local IP
AT+PING="10.0.1.1"      // ping network gate
AT+CIPSTART="TCP","10.0.1.116",2048 // setup TCP to server
AT+CIPMODE=1            // set UART-WIFI passthrough mode
AT+CIPSEND              // enter UART-WIFI passthrough mode
AT+SAVETRANSLINK=1,"10.0.1.116",2048,"TCP" // save configuration in WIFI module
After configuration, hook WIFI module to Arduino (actully I'm using stm32, but it's the same) UART pins. When power on, the WIFI module will automatically connet to AP and setup TCP link to server and enter UART-WIFI passthrough mode.

If you want to exit UART-WIFI passthrough mode, send '+++' on UART end, without '\r\n' and '+++' must be sent continuously (type '+++' in minicom won't work).

as for your questions,

Voltage divider is used, but pay attention to RXD TXD link problem. (RXD to TXD, TXD to RXD)
My WIFI module also gets hot, but working properly.
I don't know the blue LED's function, but I did remember reading about it some where, maybe in the documentation.


text:
Stepper motor not working in Arduino 101
I am trying to connect a stepper motor ( this model exactly https://create.arduino.cc/projecthub/trduunze/grove-starter-kit-for-arduino-stepper-motor-driver-66471d ) in an arduino 101 but it does not work for some reason. I have tried connecting everything ast they tell in the website with no results:

And then I tried connecting directly to the board without using the shield, and still getting nothing.
The code I am using is this :
#include <Stepper.h>
int t =0;
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;  // number of steps the motor has taken

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

void loop() {
  // set the motor speed:
  int motorSpeed = 15;
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    // step 1/100 of a revolution:
    myStepper.step(stepsPerRevolution / 25);
  Serial.println(motorSpeed);//print how fast the motor is going in the serial monitor
  }
}

Connecting the stepper motor and the driver, and launching the sketch in an arduino UNO board works perfectly, so I am really worried about that maybe the Stepper.h library might be different for the Arduino 101 but I couldn't find anything about that. I just have no idea why the project is not working in the 101 but working perfectly in the UNO. Any help or tips would be highly appreciated.
Cheers!
EDIT
After a lot of messing around, I have only been able to light up one led in the controller connecting one of the motor cables to GPIO5. None of the other GPIOS seem to work with the step motor controller.

After reading the Stepper library and searching for several, I saw that in an example using an EDISON ( I want to thanks to Guimficus for posting his code here: https://communities.intel.com/thread/99133) they changed the pinMode of the GPIOS they were using in the setup function :
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);

And after adding that seems to work like it is supposed to work.
Cheers!


text:
Receiving live astronomical coordinates on Arduino Mega using telnet and ESP8266 wifi module
I'd like to receive on my arduino live coordinates of planets of solar system. Because there are already websites listing every planet coordinates, I thought it would be easier to just use a wifi module (in my case an ESP8266) and connect the arduino to one of these website.
I have the option of getting it from this website, but I have no idea how to do that.
The other way of doing it may be to connect to Horizon via their telnet server at this adress :telnet://horizons.jpl.nasa.gov:6775
Though I know how establish a connection with this server on my computer using Putty, I have no idea how to connect my arduino to it, execute commands, and, more importantly, get data (RA and DEC) of every solar system main objects.
This is my first time using Arduino wifi module, so I have no experience with it, and I don't know what it is capable of.
Thanks a lot for your attention,
Thomas

That telnet interface is an interactive service. Getting an Arduino to interact with it is not an easy task - certainly not a task for a beginner with no experience of network programming.
A much easier task is to scrape the website since that just returns text which you then need to search through a bit at a time looking for the information you need.