text:
Servos Do Not Move to Specified Position
This code receives sine wave parameters from a serial connection, then formats and writes the sine wave positions to 8 servo motors.
The positions are successfully written to 6 of the 8 motors.
Of the two that don't work, I tried changing the motors to see if they were faulty; they are not. I changed the output pins to see if they were damaged; they are not.
I changed the order the equations are solved, and the positions are written to ensure there wasn't some bizarre timing issue. I saved a full cycle of the written positions and they output the correct numbers (i.e. the correct amplitude). You can see them here (format is "servo #" : "position"):
0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1779 1:1337 2:1750 3:1480 4:1357 5:1438 6:1452 7:1490

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1846 1:1404 2:1704 3:1434 4:1403 5:1484 6:1385 7:1423

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1880 1:1438 2:1630 3:1360 4:1477 5:1558 6:1351 7:1389

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1870 1:1428 2:1549 3:1279 4:1558 5:1639 6:1361 7:1399

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1819 1:1377 2:1485 3:1215 4:1621 5:1702 6:1412 7:1450

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1742 1:1300 2:1458 3:1188 4:1649 5:1730 6:1489 7:1527

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1662 1:1220 2:1474 3:1204 4:1633 5:1714 6:1569 7:1607

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1603 1:1161 2:1530 3:1260 4:1577 5:1658 6:1628 7:1666

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1582 1:1140 2:1609 3:1339 4:1498 5:1579 6:1649 7:1687

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1604 1:1162 2:1687 3:1417 4:1420 5:1501 6:1627 7:1665

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1665 1:1223 2:1742 3:1472 4:1365 5:1446 6:1567 7:1605

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1745 1:1303 2:1757 3:1487 4:1350 5:1431 6:1486 7:1524

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1821 1:1379 2:1728 3:1458 4:1379 5:1460 6:1410 7:1448

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

0:1871 1:1429 2:1663 3:1393 4:1443 5:1524 6:1360 7:1398

The entire code is below. The relevant section begins after if (Afreq > 0) near the bottom. The positions that do not write correctly are pos[6] and pos[7]:
/*
This is a program that recieves sine wave parameters from a serial connection in a single string.
The string is parsed and converted into numbers, which are plugged into 8 sine equations to generate
positions for each joint of the robot.
*/

#include <Servo.h>

Servo SB, SF, HB, HF, EB, EF, KB, KF;
int iAmp, iF_offset, iB_offset, iFk_offset, iBk_offset, pos[] = {0,1,2,3,4,5,6,7};
unsigned int t = 0;
unsigned long previousMillis = 0;
float fKnee_amp, fAfreq, fPhase, fGait;

void setup(){
  //Start serial stream at 115200 baud
  Serial.begin(115200);

  //Connect servos to Arduino
  HB.attach(2);
  KF.attach(3);
  SB.attach(4);
  EB.attach(10);
  HF.attach(6);
  KB.attach(7);
  SF.attach(8);
  EF.attach(11);

  delay(3000);
}

void loop(){
  char c, buffer[10];
  String readString, amp, knee_amp, afreq, gait, phase, f_offset, b_offset, fk_offset, bk_offset;
  unsigned int sine_time = 50;

  while (Serial.available() && readString.length() < 37){
    //delay to allow buffer to fill
    delayMicroseconds(100);
    if (Serial.available() > 0){
      //get one byte from serial buffer
      char c = Serial.read();
      //creates the string "readString"
      readString += c;
    }
  }

  if (readString.length() > 36){
    //see what was received
    Serial.println("The string is: " + readString);
    Serial.println(readString.length());

    //parse serial string into separate parameters
    amp = readString.substring(0, 3);
    knee_amp = readString.substring(3, 7);
    afreq = readString.substring(7, 11);
    phase = readString.substring(11, 15);
    gait = readString.substring(15, 20);
    f_offset = readString.substring(20, 24);
    b_offset = readString.substring(24, 28);
    fk_offset = readString.substring(28, 32);
    bk_offset = readString.substring(32, 36);

    //convert string values to numbers
    iAmp = amp.toInt();

    knee_amp.toCharArray(buffer, 10);
    fKnee_amp = atof(buffer);
    memset(buffer, 0, sizeof(buffer));

    afreq.toCharArray(buffer, 10);
    fAfreq = atof(buffer);
    memset(buffer, 0, sizeof(buffer));

    phase.toCharArray(buffer, 10);
    fPhase = atof(buffer);
    memset(buffer, 0, sizeof(buffer));

    gait.toCharArray(buffer, 10);
    fGait = atof(buffer);
    memset(buffer, 0, sizeof(buffer));

    iF_offset = f_offset.toInt();
    iB_offset = b_offset.toInt();
    iFk_offset = fk_offset.toInt();
    iBk_offset = bk_offset.toInt();

    //clear strings
    readString="";
    amp="";
    knee_amp="";
    afreq="";
    gait="";
    phase="";
    f_offset="";
    b_offset="";
    fk_offset="";
    bk_offset="";
  }

  //if the joints should be oscillating
  if (fAfreq > 0){
    //determine joint positions
    pos[0] = iAmp * sin(fAfreq*t) + 1500 + iF_offset;
    pos[1] = iAmp * sin(fAfreq*t) + 1522 - iF_offset;
    pos[2] = iAmp * sin(fAfreq*t + fGait) + 1500 + iB_offset;
    pos[3] = iAmp * sin(fAfreq*t + fGait) + 1446 - iB_offset;

    pos[4] = iAmp*fKnee_amp * sin(fAfreq*t + fGait + fPhase) + 1500 + iFk_offset;
    pos[5] = iAmp*fKnee_amp * sin(fAfreq*t + fGait + fPhase) + 1581 - iFk_offset;
    pos[6] = iAmp*fKnee_amp * sin(fAfreq*t + fPhase) + 1500 + iBk_offset;
    pos[7] = iAmp*fKnee_amp * sin(fAfreq*t + fPhase) + 1538 - iBk_offset;

    //get time in milliseconds
    unsigned long currentMillis = millis();

    //if the time threshold has been passed
    if(currentMillis - previousMillis >= sine_time){
      previousMillis = currentMillis;

      //write servo positions

      SB.writeMicroseconds(pos[0]);
      SF.writeMicroseconds(pos[1]);
      HB.writeMicroseconds(pos[2]);
      HF.writeMicroseconds(pos[3]);
      EB.writeMicroseconds(pos[4]);
      EF.writeMicroseconds(pos[5]);
      KF.writeMicroseconds(pos[6]);
      KB.writeMicroseconds(pos[7]);

      //increment time parameter
      t+=1;
    }
  }
}

I don't know what to try next.

Given that it's the last two that aren't working, perhaps you've got a timing problem. Now I don't know how good the compiler is about detecting common code, but you might want to make it easier for it, and perhaps speed things up by making some temporary variables:
//determine joint positions
int pos01 = iAmp * sin(fAfreq*t);
pos[0] = pos01 + 1500 + iF_offset;
pos[1] = pos01 + 1522 - iF_offset;

int pos23 = iAmp * sin(fAfreq*t + fGait);
pos[2] = pos23 + 1500 + iB_offset;
pos[3] = pos23 + 1446 - iB_offset;

int pos45 = iAmp*fKnee_amp * sin(fAfreq*t + fGait + fPhase);
pos[4] =  pos45 + 1500 + iFk_offset;
pos[5] = pos45 + 1581 - iFk_offset;

int pos67 = iAmp*fKnee_amp * sin(fAfreq*t + fPhase);
pos[6] = pos67 + 1500 + iBk_offset;
pos[7] = pos67 + 1538 - iBk_offset;


text:
Suse or Debian Linux Installation on Raspberry PI 3
Is I can install Suse or Debian Linux Installation on Raspberry PI 3. I yet to try. Based on the answer I can opt for it. Because I need in particular either of this OS for my requirement in classified project. Does this PCB design supports this OS.
Any advice or suggestions is greatly appreciated.

Flagged to close as entirely unrelated to Arduino.

I am newbie and I'm curious to know.

And we're Arduino users who don't know about Rasperry Pi. Maybe you should go and ask on the Raspberry Pi SE...? They may have a clue.

Is there a forum for Raspberry Pi [or] for that SE. I felt this is the one. So I asked over in here.

Yes - here.

Dev - This is a serious question, Why did you think this was a forum for Raspberry Pi?  Maybe there is something that can be done to stop the confusion you had from happening again.

But its about Hardware,- the Forum. I asked phenomenal, maybe Hardware bit wired so, I think it may relevant more over here and makes sense so. It can be ridden from Hold, if you hold so. Else whatever!

what does Arduino does with ARM. What is Arduino first of all. Do I need to make this inquiry as another Question.

There are many derivatives to the Arduino Uno.  Some use different processors.  The ARM based Arduinos are one of these derivatives.  That said, the ARM based Arduinos do not run an OS.  The have a boot loader and your code is what is running.  The ARM based RaspberryPis do have an OS.  And your code is just 1 of many many programs that are run in a complex time slicing paradigm controlled by the OS.  They are completely different approaches to running your code.   So much so that questions about one really do not apply to the other.

It is always best to try then post in one of the Stack Exchange groups.
This question is very general.  So the answer will also be vague as the actual porting of a Linux OS distribution to a new platform is not trivial and contains many steps.  And not all of them may have been completed to the extent to suit your needs.
Evidently you can run Debian on a Raspberry Pi.  But there are a few issues.  Look here and do the research to understand if these limitations will cause you to abandon this path.
As for Suse, evidently it is a "specially packaged version of SUSE".  So may not actually have all the features a normal Suse distribution has.  Look here to decide if it will work for you.

Suse doesn't work you mean to say.

I am not find what are features might not work in Suse over what you've sighted. Sorry for Vague sense. Have you ever tried Suse anytime as a experience, in your term.

Considering the Negative Voted, but imperative post, any feature-set could be arrived. What does Suse Lags, Will I succeed atleast with X or GNOME Windowing stuff. Refer this, http://math.stackexchange.com/questions/2099908/is-we-could-wander-on-factorial-equalities-considering-ordinals-as-discussed-in

I have not tried anything except Raspbian.    It appears to be what everyone is using.   And in the world of open source, using what everyone else has already debugged is usually the best way to go.

I am not sure why this question has not been ported to the Rraspberry Pi Stack Exchange site.

It got closed by consensus of votes before a moderator got to it, that's why. ;) Only moderators can migrate to other sites.

source: Stack Exchange

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

sort: votes


text:
Servo motor activation with pressure sensor
I need to run my servo motor within a specific pressure range, given by a pressure sensor. I don't understand how to code this. I have coded for servo motor movement but I need to activate that movement in a specific range. Please, help me.
This is my servo code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // twelve servo objects can be created on most boards
int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);
  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for(pos = 0; pos <= 30; pos += 1) {
    // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);
    // tell servo to go to position in variable 'pos'
    delay(5); // waits 15ms for the servo to reach the position
  }
  for(pos = 30; pos>=0; pos-=1) {
    // goes from 180 degrees to 0 degrees
    myservo.write(pos);
    // tell servo to go to position in variable 'pos'
    delay(5);
    // waits 15ms for the servo to reach the position
  }
  delay(1500);
}

I need to activate this servo within a 10-70 pressure range.

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


text:
Arduino Uno serial communication using USB-to-TTL converter
How to send data (Hello World) from Arduino Uno to a PC using USB to TTL/UART (PL2303 4 wires)? Why do I need to press the reset button to upload a program using PL2303?

How to send data(Hello World) from Arduino Uno to PC using USB to TTL/UART(PL2303 4 wires)?

Serial.print("Hello World");

That is, assuming it's connected to pins 0/1. Otherwise you would have to use SoftwareSerial.

why I need to press the reset button during upload a program using PL2303?

Because it lacks a DTR signal to press the reset button for you (resetting runs the bootloader).

Thanks Majenko. I have tried that code and it works when I use normal USB. But when I am trying to upload sketch with PL2303 it doesn't work. I have pressed the reset button manually just before uploading the sketch. I have tried other way.. that is.. I have uploaded the sketch with normal usb and after uploading the sketch I have changed the serial port to Pl2303. but it still not working. I am really getting confused as well as frustrated.

How is the PL2303 wired? Why are you trying to upload a sketch using it when you already have a perfectly working USB connection?

I have connected arduino rx to pl2303 tx and arduino tx to pl2303 rx and the ground pin. It's a task of mine given by my tutor.

Are you powering the board from the normal USB connection? If so you may well find you have to remove that connection and power it from some other source, since the on-board USB to UART interface may well be interfering with what you are trying to do.

Ya. I have powered my board with normal USB connection. But before I used the VCC pin of PL2303. But in the datasheet of Pl2303 they warned to not use the VCC pin (exactly don't know why). So I powered the board by normal USB. If I assign the RX/TX  on a different pin (other than 0 and 1). It's also not working. But i never tried external voltage source.

You can't assign TX and RX anywhere. They are on 0 and 1 and that is fixed. You could use SoftwareSerial instead of Serial to (just about) use any other pins, but you certainly won't ever be able to upload firmware that way...

I think you have a PL2303 board that do not have DTR or RTS line. It is a signal from Arduino IDE to Arduino Board for reset. So you must press reset button before upload.


text:
Arduino IDE documentation for WiFi.connected()
I'm including this library "ESP8266WiFi.h" at the top of my sketch.
I can find documentation on WiFiServer.available(), but didn't find for WiFi.connected(), which is called in a server sketch after getting the client.
Clearly it's a test whether (once? I believe) the client is connected or not (and hasn't been explicitly closed in the server's side). It may seem obvious but some documented info would be helpful though.

You'll find it defined in WifiClient.h. The version I am using is, in WifiClient.cpp:
uint8_t WiFiClient::connected() {
  if (!_client)
    return 0;
  return _client->state() == ESTABLISHED || available();
}

Thank you. I think I will have to read the code thoroughly. Meanwhile I hope someone documents it...

Complain to the maintainers of the core. It's their responsibility.


text:
Need help with sending Arduino data to web page with ESP8266
I am developing a system that reads data from an LM35 temperature sensor and forwards it to a web page using an Arduino Uno and a ESP8266 WiFi Module. The data flow is as follows:
LM35 --> Arduino Uno --> ESP8266 (Having a web server) --> Webpage
The Uno sends data to the ESP8266 every SAMPLE_RATE seconds (4 seconds in my example) but the ESP8266 keeps updating the web page as it is a dynamic web page running AJAX. The problem is that I can see the data updating only once in a while (I assume when the 4 second delay aligns with the instant when the ESP8266 updates the value on the web page).
How can I make it so that even if The Uno doesn't send new values (during the 4 second gap), the ESP8266 keeps updating the web page with the old values? I have tried numerous times but have failed. Here is my code so far:
ARDUINO SIDE:
#include <SoftwareSerial.h>
#include <String.h>

//a Header for the Filtering Algorithm

//*******************************************************************/
//#include "Filter.h"
//*******************************************************************/

//Set RESET PIN for ESP8266

//*******************************************************************/
#define RST_PIN_ESP8266 13
//*******************************************************************/

//Define Baud rate for Serial Communication and ESP8266 Software Serial
//*******************************************************************/
#define SERIAL_BAUD_RATE 9600
#define ESP8266_SOFT_SERIAL_BAUD_RATE 9600
//*******************************************************************/

//LM35 Temperature sensor used for this code
//*******************************************************************/
#define LM35 A0
//*******************************************************************/

//Define Sensor sampling rate
//*******************************************************************/
#define SAMPLE_RATE 4000
//*******************************************************************/

//Code Features . . Uncomment to enable
//*******************************************************************/
//#define LM35_RAW_DEBUG
//#define TEMP_READ
//#define PRINT_DEBUG
#define MEASURE_SALINE
//*******************************************************************/
//ESP8266 Software Serial Object
//*******************************************************************/
SoftwareSerial ESP8266_Serial(6,7);
//*******************************************************************/

//Global Variables
//*******************************************************************/
float tempC;
long rawValue = 0, initCount = 0;
int initRawValue = 0, i, START_VALUE = 0;
int SALINE_STARTED = 0, SALINE_IN_PROGRESS = 1, SALINE_EXHAUSTED = 2;
int saline_status_flag = 0;
String finalMSG;
//*******************************************************************/

//Needed objects for time counting and filtering
//*******************************************************************/
unsigned long StartTime = millis();
//ExponentialFilter<int> ADCFilter(5, 0);
//*******************************************************************/

void setup() {
  long rawValue = 0, initCount = 0;
  int initRawValue = 0, i;
  //Set up Serial Communication
  Serial.begin(SERIAL_BAUD_RATE);
  ESP8266_Serial.begin(ESP8266_SOFT_SERIAL_BAUD_RATE);
  pinMode(RST_PIN_ESP8266, OUTPUT);
  Reset_ESP8266();
  while(ESP8266_Serial.available()) {
    getIP();  // Obtain IP for ESP8266
  }
  delay(1000);
  //Increase accuracy
  analogReference(INTERNAL);
  //Start Sensor Calibration
  #ifdef MEASURE_SALINE
    Serial.print(". . . CALIBRATING SYSTEM . . .\n");
    #ifdef PRINT_DEBUG
      Serial.println("\n\nTime Elapsed  :\n\n");
    #endif

    here:
    unsigned long currentTime = millis();
    unsigned long elapsedTime = currentTime - StartTime;

    #ifdef PRINT_DEBUG
      Serial.println(elapsedTime);
    #endif

    if(elapsedTime < 20000) {
      initCount++;
      rawValue += analogRead(LM35);
      #ifdef PRINT_DEBUG
        Serial.println(rawValue);
      #endif
      goto here;
    }
    currentTime = 0;
    elapsedTime = 0;
    rawValue = rawValue / initCount;
    //Averaging from 5000 sensor samples
    initRawValue = rawValue;
    START_VALUE = initRawValue;
    Serial.println("\n. . . CALIBRATION COMPLETE . . .");
    Serial.print("\nInitial Raw LM35 Value  : ");
    Serial.print(START_VALUE);
    Serial.print("\n\n");
    Reinitialize_Variables();
    delay(2000);

    #ifdef PRINT_DEBUG
      Serial.println("\nLM35 Sample Count:\n");
      Serial.println(initCount);
    #endif

  #endif
  initCount = 0;

  #ifdef LM35_RAW_DEBUG
    Serial.println("\n. . . STARTING LM35 DEBUG READING . . .\n\n");
  #endif

  #ifdef MEASURE_SALINE
    Serial.println("\n. . . STARTING SALINE MONITORING. . .\n\n");
  #endif
}

void loop() {
  #ifdef MEASURE_SALINE
    Measure_Saline();
  #endif

  #ifdef LM35_RAW_DEBUG
    rawValue = analogRead(LM35);
    Serial.println(rawValue);
  #endif

  #ifdef TEMP_READ
    Read_Temp();
  #endif

  Reinitialize_Variables();
}

void Measure_Saline() {
  int dont_print_flag = 0;
  unsigned long StartTime = millis();
  //Take readings (SAMPLE_RATE times) and average them
  here:
  unsigned long currentTime = millis();
  unsigned long elapsedTime = currentTime - StartTime;

  #ifdef PRINT_DEBUG
    Serial.println(elapsedTime);
  #endif

  if(elapsedTime < SAMPLE_RATE) {
    initCount++;
    rawValue += analogRead(LM35);
    #ifdef PRINT_DEBUG
      Serial.println(rawValue);
    #endif
    goto here;
  }
  currentTime = 0;
  elapsedTime = 0;
  rawValue = rawValue / initCount;

  #ifdef PRINT_DEBUG
    Serial.print("initCount  : ");
    Serial.print(initCount);
  #endif
  if(saline_status_flag != SALINE_EXHAUSTED) {
    if(rawValue < START_VALUE) {
      saline_status_flag = SALINE_STARTED;
    } else if(rawValue == START_VALUE) {
      saline_status_flag = SALINE_IN_PROGRESS;
    } else if(rawValue > START_VALUE) {
      START_VALUE = rawValue;
      delay(1000);
      rawValue = analogRead(LM35);
      delay(10);
      if(rawValue > START_VALUE) {
        saline_status_flag = SALINE_EXHAUSTED;
        dont_print_flag = 1;
        Serial.print(rawValue);
        Serial.print("  Saline bottle EXHAUSTED\n");
        finalMSG = (String(rawValue) + " EXHAUSTED\n");
        ESP8266_Serial.println(finalMSG);
      }
    }
    //Saline Therapy Ongoing
    if((saline_status_flag == SALINE_STARTED || saline_status_flag == SALINE_IN_PROGRESS) && dont_print_flag == 0) {
      Serial.print(rawValue);
      Serial.print("  Saline Therapy IN PROGRESS\n");
      finalMSG = (String(rawValue) + " IN PROGRESS\n");
      ESP8266_Serial.println(finalMSG);
    } else if(saline_status_flag == SALINE_EXHAUSTED && dont_print_flag == 0) {
      //Saline Exhausted
      Serial.print(rawValue);
      Serial.print("  Saline bottle EXHAUSTED\n");
      finalMSG = (String(rawValue) + " EXHAUSTED\n");
      ESP8266_Serial.println(finalMSG);
    }
    START_VALUE = rawValue;
  } else {
    Serial.print("  Saline bottle EXHAUSTED\n");
    finalMSG = (String(rawValue) + " EXHAUSTED\n");
    ESP8266_Serial.println(finalMSG);
  }
  delay(200);
}

void Read_Temp() {
  rawValue = analogRead(LM35);
  tempC = rawValue * 0.48828125;
  tempC = rawValue / 9.31;
  Serial.println(tempC);
  delay(2000);
}

void Reinitialize_Variables() {
  initCount = 0;
  rawValue = 0;
  initRawValue = 0;
  i = 0;
}

void getIP() {
  Serial.println(ESP8266_Serial.readStringUntil('\n'));
}

void Reset_ESP8266() {
  pinMode(RST_PIN_ESP8266, OUTPUT);
  digitalWrite(RST_PIN_ESP8266, HIGH);
  // (RST_PIN_ESP8266 = 1 -> RESET = 0 so ESP8266 RESET FALSE)
  delay(1000);
  digitalWrite(RST_PIN_ESP8266, LOW);
  // (RST_PIN_ESP8266 = 0 -> RESET = 1 so ESP8266 RESET TRUE)
  delay(1000);
  digitalWrite(RST_PIN_ESP8266, HIGH);
  // (RST_PIN_ESP8266 = 1 -> RESET = 0 so ESP8266 RESET FALSE)
  delay(50);
}

ESP8266 side:
/*
 * This Code is for the ESP8266 WiFi Module. It builds a website running AJAX (Asynchronous JavaScript and XML)
 * which allows this webpage to update itself without having to refresh itself which may not be resource friendly
 */

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

#define DEVICE_ID 1

ESP8266WebServer server(80);
const char* ssid="COLDSPOT";  // WiFi Access Point to connect to
const char* password="1234567890"; // Password for the Access Point
String webSite,javaScript,XML;

void buildWebsite() {
  buildJavascript();
  webSite = "<!DOCTYPE HTML>\n";
  webSite += javaScript;
  webSite += "\n";
  webSite += "

SALINE MONITORING:

\n";
  webSite += "STATUS = \n";
  webSite += "\n";
  webSite += "\n";
}

void buildJavascript() {
  javaScript = "\n";
}

void buildXML() {
  XML = "<?xml version='1.0'?>";
  XML += "<response>";
  XML += DataFromArduino(); //incoming data from Arduino. It means it is the value of mapping function.
  XML += "</response>";
}

String DataFromArduino() {
  String coming;
  if(Serial.available()) {
    while(Serial.available()) {
      coming = Serial.readStringUntil('\n');
      delay(1);
    } // it is getting via serial port.
    return coming;
  } else {
    return coming;
  }
}

void handleWebsite() {
  buildWebsite();
  server.send(200,"text/html",webSite);
}

void handleXML() {
  buildXML();
  server.send(200,"text/xml",XML);
}

void setup() {
  Serial.begin(9600);
  WiFi.begin(ssid,password);  //trying to connect the modem
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  WiFi.mode(WIFI_STA);
  Serial.println("\n\n. . . BOOTING ESP8266 . . .\n");
  Serial.print("DEVICE ID : ");
  Serial.print(DEVICE_ID);
  Serial.print("\n");
  Serial.print("CONNECTED TO ACCESS POINT :  ");
  Serial.println(ssid);
  Serial.flush();
  Serial.println(WiFi.localIP());
  //it is sending the IP to Arduino's port. So I can see the IP on Serial Monitor
  Serial.flush();
  server.on("/", handleWebsite);
  //it is all about setting of server.
  server.on("/xml",handleXML);
  server.begin();
}

void loop() {
  server.handleClient();
}

Please note that I have already changed the baud rate of the ESP8266 to 9600. I am using THIS ESP8266 Module.

If you take the variable String coming out of the function DataFromArduino() and make it a global variable (by adding it to the line after String website1).  That way it will store its value between calls to  DataFromArduino() and return the same result if it has had nothing new.


text:
Arduino Serial Communication with Python: sending an array
I am a bit new to both Arduino and Python. My aim is to send commands to Arduino to run a stepper motor. I need to send an array containing the parameters. After consulting many earlier posts like:
https://stackoverflow.com/questions/27639605/send-a-list-of-data-from-python-to-arduino-using-pyserial
Send multiple int values from Python to Arduino using pySerial
I wrote my Arduino code:
long  incoming[3];

void setup() {
  pinMode(13, OUTPUT);
  Serial.begin(9600);
  Serial.println("Ready");
}

void loop() {
  if(Serial.available()) {
    for (int i = 0; i < 3; i++) {
      incoming[i] = Serial.read();
    }
    Serial.println(incoming[0]);
    Serial.println(incoming[0]);
    Serial.println(incoming[2]);
  }
}

And the Python(2.7) code:
from time import sleep
import serial
import struct
ser = serial.Serial('COM6', 9600)

while True:
     ser.write(struct.pack('>iii',2000,10,220))
     print ser.readline()
     sleep(.5)

Now coming to the problem:

The values printed on the Python shell are completely wrong, including negative values.
If I use >BBB instead of >iii, I am getting the correct result, but I can't go beyond 255, the integer limit. There is a small catch here also, the initial two sets are giving minus values and then it becomes alright.
Further, is there any way to interrupt a running void loop?

Any help is deeply appreciated.

This may help clear up some misconceptions: https://hackingmajenkoblog.wordpress.com/2016/02/01/reading-serial-on-the-arduino/

If I use >BBB instead of >iii... That's because "B" is a byte. So you end up sending 3 bytes:
struct.pack("BBB", 1, 2, 3)
\x01\x02\x03

"i" is an int and has a size of 4, so you send 4*3 = 12 bytes:
struct.pack("iii", 1, 2, 3)
\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00

Serial.read() reads 1 byte at a time, so you need to read 4 bytes for each value.

Here's a function to read a 32-bit int. The drawbacks of this method are that a) it will block until 4 bytes have been read. And b) there's no way to tell if some data has been lost. There are more robust ways to send data with Start-of-Message, End-of-Message, and Check-sum chars. Also, the function assumes the data is sent with the LSB first. But I'll just put this here as an example.
// Helper macro to merge 4 bytes
#define TO_INT32(a,b,c,d) (((d)<<24)|((c)<<16)|((b)<<8)|(a))
int32_t read_int()
{
  uint32_t result[4];
  for (int i = 0; i < 4; i++) {
    // Wait for data at the port
    while (!Serial.available());
    result[i] = Serial.read();
  }
  return TO_INT32(result[0], result[1], result[2], result[3]);
}

You can much more easily send an array between Python and Arduino using the inter-compatible libraries SerialTransfer.h and pySerialTransfer. Using libraries like this ensures reliable and robust communication between Python and your Arduino.
SerialTransfer.h is installable via the Arduino IDE's Libraries Manager and comes with many examples. The package pySerialTransfer is pip-installable.

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


text:
Talkie Library/Speech synthesis options for Raspberry Pi Zero
I am porting my Arduino sketch from Arduino Uno to Raspberry Pi 2040 zero (the blue board that is about postage stamp sized). It uses the talkie library here.
https://github.com/ArminJo/Talkie
But the above talkie library is not supported on Raspberry Pi 2040 zero. Is there a similar alternative speech synthesis library for Raspberry Pi 2040 zero? Or a substitute speech library for Raspberry Pi 2040 zero? A speech library that will fit into a stock unmodified Raspberry Pi 2040 board.

@jsotola It is  obviously a  reasonable question to ask on an Arduino

@jsotola Site.To answer your question the Raspberry Pi board can be programmed as Arduino through the Arduino ide e.g. as done in this youtube video here for examplr https://www.youtube.com/watch?v=X0ro3TPzbwA

I don't know why people think it's off topic. Despite you indicating otherwise, maybe they think you're talking about the RPI Zero, as in the thing more related to a full sized Raspberry Pi (the SBC) and not something which is in fact closer to an RPI Pico (the dual cortex-m0 based thing) or Arduino NANO RP2040 Connect to take a official example. Anyway, it's a question about an Arduino library being supported/replaced when moving to another board supported by the IDE and build system. This should not a problem for this site.

@chez, If you are "porting", maybe try to port the library, there is not much porting need for the Arduino sketch as the API for different boards are very much the same. The library already supports ARM Cortex-M0 (such as SAMD, Teensy), and ARM Cortex-M3 (blue pill), both are similar to Pico RP2040, probably changes are the timer to be used and pin(s) for the PWM output.

Maybe provide a link to (or picture) of the "blue board that is about postage stamp sized" so that it is really clear what you're talking about.

Talkie is for Arduino. For RPI zero, use PicoTTS or ESPeak-NG. https://github.com/ihuguet/picotts
https://github.com/espeak-ng/espeak-ng
If you later want to switch to any other Chip, you can try ADAM-Speech-Synthesizer based on the SPO256A-AL2 chip.
https://www.pcbway.com/project/shareproject/ADAM_Speech_Synthesizer_ae73d03e.html

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


text:
Converting raw data of IIS2MDC into angle
I do not know that this is a good place for asking question but I have a 3 axis magnetometer IIS2MDC. I used this with Arduino. I downloaded the library IIS2MDC.h in Arduino IDE. I used example code of IIS2MDC.h library for reading magnetometer data.  I have 3 axis raw data.
My question is that how to convert magnetometer data into degrees?
Is there any reference or solution for this?

Welcome to SE/Arduino! The device and its library should have documentation, and I would expect example code to show such conversions. Please [edit] your question to provide links to that, and add why it does not help you. -- OT: A library consists in C++ projects commonly of two parts, the header file and the library file. The former is "just" for convenience, the important file is the second one. Apparently the IDE does everything automagically correct, but please be aware of such details.

@EDExpert, do edit your question to make it better. Just so you know:  In the many stackexchange web sites, it is better to edit your question and for others to edit their answer to resolve the unexpected. In other words: Ask your question as if in front of an audience any of whom may have the same problem that needs resolving.

It is likely the magnetometer needs to be calibrated before it can be used. Before calibration is applied to the magnetometer's output values, comparing any 2 of the 3 orthogonal sensors will be difficult.
Search and learn the terms hard iron and soft iron distortion / calibration with respect to magnetometers. Hard iron distortion is an offset error.  Find the maximum (point a particular magnetometer toward magnetic north) and the minimum (point the same magnetometer away from magnetic north) values of one of the magnetometers. Calculate an offset value such that when applied the maximum and minimum magnitudes are the same. Soft iron distortion is a magnitude error. Find the maximum and minimum values for all 3 sensors. From this find the total range of all 3 sensors. Arbitrarily pick one of the sensors ranges and calculate magnitude adjustment values for the remaining sensor ranges such that after applying them all 3 sensors have the same range.
At this point let us narrow the scope of the electronic compass to simplify the project.  Let us constrain the compass to only be used on a table which is parallel to the surface of the earth. At which point we only need to use 2 of the sensors (the two that lie in the plane of the table).
To calculate the angle the magnetometer is pointing with respect to magnetic north we take the arctangent of the ratio of the 2 magnetic sensor which lie in the plane of the table. However, this math function only gives us angles for half the desired angles. Fortunately, the C programming math library contains a special function atan2() which can return a full circle of angles (from here):

Synopsis. The atan2() function divides the first argument by the second and returns the arc tangent of the result, or arctan( y / x ) . The return value is given in radians, and is in the range -π ≤ atan2( y , x ) ≤ π.

I try hard iron and soft iron distortion / calibration but i am unable to get correct values. I convert heading values of magnetometer into degrees using atan2(y/x) * 180/ PI equation but i got few random values i did not get 0 to 360 degree values. So how can i work my IIS2MDC chip as compass IC and get accurate degrees according to direction?

Take it one step at a time. Before finding the arc tan, make sure the way your sensor is held that you are using the 2 sensors that are always parallel (not tilted) with respect to the earth's surface.  Then, after adding or subtracting the calibrated offset and multiplying with the calibrated magnitude that the 2 values raise when that sensor is pointed to north and lowers when pointed away by the same or nearly the same amount. That the negative of the maximum for a particular sensor is the same or nearly the same as the minimum. After that works, then take the arc tan.


text:
Custom PCB based on the Adafruit PyBadge with Multiple SPI interfaces for SD Card and other devices
I'm currently working on a tracking device with multiple sensors on a custom PCB. The device uses Narrowband LTE, SPI flash, and an SD card, all managed by an ATSAMD51J19A microcontroller. To streamline development.
Based on past experiences, I encountered issues using a single SPI bus to handle both sensors and the SD card simultaneously, which led to conflicts and performance problems. To address this, I created a custom SPI bus named SD_SPI by following the instructions in this great manual.
However, when I tried to initialize the SD card using the custom SPI bus, the initialization always failed. To troubleshoot, I switched to a software SPI implementation, and the SD card worked immediately without any issues. This suggests that the problem might be related to the setup of the SDFAT library.
I suspect the problem to be somewhere in the SD configuration since i haven't found any example of what i'm trying to do so i just did
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(1), &SD_SPI)

I'm hoping for advice from someone more knowledgeable.

#include "SdFat.h"
#include "wiring_private.h"
#include <Arduino.h>
#include <SPI.h>

#if SPI_DRIVER_SELECT == 0  // Must be set in SdFat/SdFatConfig.h

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 3
//
// Chip select may be constant or RAM variable.
const uint8_t SD_CS_PIN = 5;
//
// Pin numbers in templates must be constants.
const uint8_t MISO_PIN = 6;
const uint8_t MOSI_PIN = 9;
const uint8_t SCK_PIN = 28;

// SdFat custom SPI template
SPIClass SD_SPI(&sercom1, MISO_PIN, SCK_PIN, MOSI_PIN, SPI_PAD_2_SCK_3, SERCOM_RX_PAD_2);

#if ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(1), &SD_SPI)

#else  // ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(0), &SD_SPI)
#endif  // ENABLE_DEDICATED_SPI

#if SD_FAT_TYPE == 0
SdFat sd;
File file;
#elif SD_FAT_TYPE == 1
SdFat32 sd;
File32 file;
#elif SD_FAT_TYPE == 2
SdExFat sd;
ExFile file;
#elif SD_FAT_TYPE == 3
SdFs sd;
FsFile file;
#else  // SD_FAT_TYPE
#error Invalid SD_FAT_TYPE
#endif  // SD_FAT_TYPE

void setup() {
  // turn on the SD-Card
  pinMode(43,OUTPUT);
  digitalWrite(43, HIGH);
  delay(5000);

  SD_SPI.begin();
  delay(200);

  pinPeripheral(6, PIO_SERCOM);    // SD_SPI MISO
  pinPeripheral(28, PIO_SERCOM);   // SD_SPI MOSI
  pinPeripheral(9, PIO_SERCOM);    // SD_SPI SCK

  Serial.begin(9600);
  // Wait for USB Serial
  while (!Serial) {
    yield();
  }
  Serial.println("Type any character to start");
  while (!Serial.available()) {
    yield();
  }

  Serial.println("starting");
  delay(500);
  if (!sd.begin(SD_CONFIG)) {
    sd.initErrorHalt();
  }

  if (!file.open("HARDSPI.txt", O_RDWR | O_CREAT)) {
    sd.errorHalt(F("open failed"));
  }
  file.println(F("This line was printed using software SPI."));

  file.rewind();

  while (file.available()) {
    Serial.write(file.read());
  }

  file.close();

  Serial.println(F("Done."));
}
//------------------------------------------------------------------------------
void loop() {}
#else  // SPI_DRIVER_SELECT
#error SPI_DRIVER_SELECT must be two in SdFat/SdFatConfig.h
#endif  // SPI_DRIVER_SELECT

If you are using the SPI bus for multiple devices, it might help to switch to SHARED_SPI instead of DEDICATED_SPI in your SdSpiConfig: #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(0), &SD_SPI)


text:
Neopixel Painter - Need to change few lines. Not sure where to start
My name is Maria and I'm learning programing in high school.
I'm working on a birthday present for my mom, want to make a mood light. Using light painter, a neopixel strip, and an arduino.
https://github.com/adafruit/NeoPixel_Painter
I found the part, which reads the bmp line by line a very innovative way to make custom animations.
But some tweaks are needed. (I've tried to make them, believe me, oh I've tried.) So, i was wondering if i can ask someone a favor and teach me how to modify the code (like, comment on parts that been changed.)
Basically, what I want to be changed is, to loop the current bmp until 'next' button is pressed, rather than hold the trigger. Also, I'm not sure if the code try to save power, but it can be disabled since it will run from a power supply.
Here is the part that makes you hold the trigger button (i think)
  for(;;) {
    while(!(TIFR1 & _BV(TOV1)));               // Wait for Timer1 overflow
    TIFR1 |= _BV(TOV1);                        // Clear overflow bit

    show();                                    // Display current line
    if(stopFlag) break;                        // Break when done

    if(++block >= nBlocks) {                   // Past last block?
      if(digitalRead(TRIGGER) == HIGH) {       // Trigger released?
        memset(sdBuf, 0, N_LEDS * 3);          // LEDs off on next pass
        stopFlag = true;                       // Stop playback on next pass
        continue;
      }                                        // Else trigger still held
      block = 0;                               // Loop back to start
    }
    card.readBlock(block + firstBlock, sdBuf); // Load next pixel row
  }

And the complete code: https://github.com/adafruit/NeoPixel_Painter/blob/master/NeoPixel_Painter.ino
Anyway, Since I'm talking to an experts right now, I have this idea to remote control the code! from  another arduino!
My, probably retarded idea is, to run an IR remote code on a second arduion, than when it receives a signal, send a simulated button press to the first ardu playing the bmp! Is that even possible? Just wondering.
Cheers
Maria

I can't see anything there that tries to save power. Remote controlling should be easy enough, grab some IR transmitter examples. It should be easy enough to set up a transmitter on one Arduino, and a receiver on another. Experiment with that first, before trying to control lights.

I think you need something like this.
  for(;;) {
    while(!(TIFR1 & _BV(TOV1)));               // Wait for Timer1 overflow
    TIFR1 |= _BV(TOV1);                        // Clear overflow bit

    show();                                    // Display current line

    if(++block >= nBlocks) {                   // Past last block?
      block = 0;                               // Loop back to start
    }

    if(digitalRead(NEXT_PIN_OR_SOMETHING) == LOW) {       // Next button pressed
      break; // Break out of for-loop
    }

    card.readBlock(block + firstBlock, sdBuf); // Load next pixel row
  }


text:
Error using nRF24L01+ with ATmega328P-PU. Works fine on Uno
I am trying to use a nRF24L01+PA with an ATmega328P minimal breadboard system. I first connected the module to my Uno and verified it with the "scanner" example sketch from the rf24 library, which showed:
STATUS       = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0xe7e7e7e7e7 0xc2c2c2c2c2
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR      = 0xe7e7e7e7e7
RX_PW_P0-6   = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA        = 0x00
EN_RXADDR    = 0x03
RF_CH        = 0x4c
RF_SETUP     = 0x07
CONFIG       = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model        = nRF24L01+
CRC Length   = 16 bits
PA Power     = PA_MAX

It also shows the readings from each channel after; I just omitted that part.
Removing the chip and reconnecting it to my breadboard ATmega, which has been bootloaded and tested with the blink sketch, I get the following:
STATUS       = 0x00 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=0 TX_FULL=0
RX_ADDR_P0-1     = 0x0000000000 0x0000000000
RX_ADDR_P2-5     = 0x00 0x00 0x42 0x42
TX_ADDR      = 0x1042082184
RX_PW_P0-6   = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA        = 0x00
EN_RXADDR    = 0x00
RF_CH        = 0x00
RF_SETUP     = 0x00
CONFIG       = 0x00
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model        = nRF24L01
CRC Length   = Disabled
PA Power     = PA_MIN

I double-checked all my wires against an ATmega328P pin map and everything checks out.
Furthermore, running the "gettingstarted" sketch on my Uno returns the correct result in the serial monitor where the chip starts in receiving mode and waits for instructions or to receive packets. And because I don't have the other chip set up yet, nothing shows up. However, when I run the exact same program on my breadboard ATmega, I get the following right after it finishes uploading.
RF24/examples/GettingStarted
*** PRESS 'T' to begin transmitting to the other node
Sent response 4194829060
Sent response 4194829060
Sent response 4194829060
Sent response 4294967295
Sent response 4294967295
Sent response 4294967295
Sent response 0
Sent response 4294967295
... yada yada yada

The fact that it is picking up any signals doesn't make sense as I am not transmitting from anything... yet.
The only MAJOR difference between my breadboard setup and the uno is the uno is running off USB 5V and the antenna is getting power from the 3.3V pin. On my breadboard, I have my usb2serial jumpered to 3.3V right off the bat and it is running the ATmega328P with a 16MHz crystal basically at 3.3V (waiting on my 3.3V regulators to arrive this Friday so I can run the chip at 5 and drop down to 3.3 just for the chip, as it is a potential solution I have in mind but in the meantime I am asking for other possibilities). Yes I know it is low but so far other sketches like the blink work, and I am running the chip in receive mode anyways.
I am lost and would appreciate some guidance.
Thank you.

Generally, a debugging question must include both the circuit and the code.   Using a 3.3v output of a serial converter to power a project including a radio is dubious even for the radio version without the power amplifier yours has.  You haven't documented the capabilities of your converter, but typically their regulators can only supply a small amount of current.

The code is what is included in the rf24 library and I'm assuming someone who can offer insight into a fix for the problem probably has used the code before (since they would have used the rf24 library before), so I didn't copy and paste in the huge block of stock code. Regarding the serial converter, if I were to run it at 5V (which I did try later), would the supplied current be noticeably smaller than my Uno? If not, I would think it should work. I tried powering the ATmega @ 5V and using my Uno's 3.3V to power the nrf24 chip. Still same results.

The ATmega328P can't run at 16MHz at a supply voltage of only 3.3V (check the datasheet). Either raise the voltage or lower the frequency.
Also note that 16mHz would be 16 milliherz (16E-3), so you probably mean 16MHz, i.e. 16 megahertz (16E6).
Remember that the nRF24L01+ is a 3.3V device, so don't connect it to the ATmega's Vcc when changing the supply voltage to 5V.
The IO pins are 5V tolerant, so that's not an issue.

Edited the typo. Understood regarding the undervolting. At 16MHz I believe it needs a minimum of 3.7ish, at least per mfg data. But, as some have seen, the board will run at 3.3V and so far the atmega has been able to load sketches at 3.3V so that's why I was sort of ruling out that as the problem.
Got it regarding the nrf24l01 chip voltage. Though if I'm getting a solid 3.3V supply to the nrf24 chip, why does it output all these weird readings. Even the reading of the chip's information is not right. If an undervolted atmega causes these issues, I'd think it wouldn't even print to serial

You don't know that. Behavior outside of the specs is undefined. It may work for a simple blink sketch, and not for more advanced sketches that make use of the SPI peripheral, for example. Last time I tried to run an ATmega328P on 3.3V @16MHz, it worked for 50% of the time.

This is however  unlikely to be the issue.

I jumpered the serialusb to 5V so the breadboard gets 5V so we can rule that problem out. Then i connected the 3.3V and GND from my Uno to the V+ GND of the nrf24l01 chip, so it runs off separate power from the breadboard atmega (IO pins of nrf24l01 5V tolerant so it would be fine getting signals from the atmega at 5V). Still same results with all 0's.

I tried that too and failed too. Then I moved to another project and postponed this for a while, but my web searches suggests, that the NRF needs a lot and hard current sometimes (at start/conneting), and atmega's internal cannot offer that. Also had seen a lot of NRF shields consiting basically only of another foot-print (for breadboard) and 3v3 stabilizer (and requiring 5V power) to believe that it is true. Many people wrote, that those shields works like charm.


text:
Reconnect to I2C with a different address (ATTiny85)
My project requires to reconnect to an I2C bus as a slave. I can't reset my ATTiny physically because I2C + my project + a pin to trigger the reset isn't possible due to the limited amount of pins available on the ATTiny85. I searched the reference and different forums. If there was an answer to my question, I couldn't find one.
Thanks in advance.
(I want to try to make a plug-and-play kind of experience with a product. I want the chip to join with a defined address (100 or so), get a new address from the master and then reconnect to the I2C bus).

A jump to 0 can "fake" a reset, but no guarantees that it does what you want.

I considered that before but i'm not sure if it stops the i2c connection aswell

Or you could use the watchdog.

The Watchdog works perfectly. I had to use modified code that works with the ATTINY that I found on a Blog. https://bigdanzblog.wordpress.com/2015/07/20/resetting-rebooting-attiny85-with-watchdog-timer-wdt/

USI is used to implement I2C on an ATtinyX5. The I2C address is not a hardware register instead this is done in software. It easy both to change address but also listen for several address. Please read the library source code and USI hardware manual for further details.

You only need to reinit the I2C slave.
The TinyWireS lib I found lets you just call TinyWireS.begin() with the new slave address. Though it doesn't have a way to stop the I2C connection. But the lib is hackable enough that with the ATTiny's specsheet you can add an end() to it.
However I believe that it may be better if the newly connected ATTiny acts as a master first and requests a free address from a known fixed slave acting as a dhcp server.


text:
Trying to connect a 1.3" IIC OLED display to an Arduino M0 board (not Uno)
I'm trying to connect an OLED display to the Arduino M0. I got the code example (ssd1306_128x64_i2c) from the Adafruit SSD1306 library I downloaded.
Video showing at 8:14 how it should look
However, when I upload the code to the board most of the display just lights up with no motion. It's only in the bottom that you can see the program is running, showing part of the different shapes.
After I uploaded it the first time I didn't change anything but now the compiler gives an error message saying that one display setting must be specified in SSD1306.h
I've tried setting the display size in the library header file which looks like this:
Displays
-----------------------------------------------------------------------
The driver is used in multiple displays (128x64, 128x32, etc.).
Select the appropriate display below to create an appropriately
sized framebuffer, etc.

    SSD1306_128_64  128x64 pixel display
    SSD1306_128_32  128x32 pixel display
    SSD1306_96_16

#define SSD1306_128_64
//#define SSD1306_128_32
//#define SSD1306_96_16

But the same error message appears in the compiler.
Does anybody know how I can fix this?
Thank you.

if your size is wrong but something shows up, it's not IIC, it's the screen settings.

The Adafruit library works with the Adafruit oled display. There are about four or five different oled types. If you don't have a Adafruit oled, then you could try a few different modes of the U8g2 library, or buy a Adafruit oled.

That header part should look like this (notice the comment starts and ends):
    /*=========================================================================
    SSD1306 Displays
    -----------------------------------------------------------------------
    The driver is used in multiple displays (128x64, 128x32, etc.).
    Select the appropriate display below to create an appropriately
    sized framebuffer, etc.
    SSD1306_128_64  128x64 pixel display
    SSD1306_128_32  128x32 pixel display
    SSD1306_96_16
    -----------------------------------------------------------------------*/
#define SSD1306_128_64
//   #define SSD1306_128_32
//   #define SSD1306_96_16
/*=========================================================================*/

If it compiles but doesn't work try to replace the I2C address of Adafruits 128x64 module (0x3D) by the address often used in Chinese modules (0x3C):
display.begin(SSD1306_SWITCHCAPVCC, 0x3D);

to
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

If that doesn't work, use an I2C scanner to find the address of the connected module.

Thank you Pylon. I reloaded the library and the error message regarding choosing the display stopped appearing. However, I think there migt be something wrong with the board as my computer can't connect to it. But your answer solved the problem. :)


text:
NodeMCU Modbus interfacing with Pressure Multi-Switch
I've been trying to interface between a NodeMCU and a Dotech DPX200 Pressure Multi-Switch over Modbus RS485 using a MAX485 Module for the past few weeks, going through nearly every Modbus post on this site  with no luck.
As my access to the multi-switch can be limited at times, I've also tried using several simulators like ModScan64, Simply Modbus Master/Slave, Modbus Poll etc. but could get none to work.
I'd like to know if the Modbus device's Slave ID has to be set on the device itself or the NodeMCU? Also to get the "Display of low pressure value" the address given in the manual is 40023. How would I write the NodeMCU code to read that value using either the ModbusRtu, ModbusMaster or any other appropriate library?

I've added the DPX200's Manual link with my NodeMCU script and wiring diagram, and would appreciate any help from you.

#include <ModbusMaster.h>
#define MAX485_TX_ENABLE  12

int myInts[6];
ModbusMaster node;

void preTransmission(){
  digitalWrite(MAX485_TX_ENABLE, 1);
}

void postTransmission(){
  digitalWrite(MAX485_TX_ENABLE, 0);
}

void setup(){
  Serial.begin(9600);
  Serial1.begin(9600, SERIAL_8N1);
  pinMode(MAX485_TX_ENABLE, OUTPUT);
  digitalWrite(MAX485_TX_ENABLE, 0);
}

void loop(){
  uint16_t k = 0,Status;
  node.begin(1, Serial1); //Slave ID = 1?
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
  Serial.println(i);
  Status = node.readHoldingRegisters(0x0023, 5); //Since address is 40023 to 40027
  if ( (Status == node.ku8MBSuccess) ){
     Serial.print("\nIDK: ");
     //Serial.println(node.getResponseBuffer(0));
     for (k = 0; k <= 5; k++ ){
        Status = node.readHoldingRegisters(k, 1);
        Serial.println(node.getResponseBuffer(0));
        delay(0);
     }
  }
}

the slave id is set in slave. the id is in the documentation of the sensor. it is 1 (and can be set in register 40063)

@Juraj Thank you for the info on Slave ID. I'm sorry but could you please explain what you meant in the second comment?

@Juraj Thanks a ton. So is the solution to just change it to Serial? Sorry if it's a silly question but I don't have much experience with this.

Now you have node.begin(1, Serial1), but you can't use Serial1 for RS485 because Serial1 doesn't have RX pin
According to the picture you wired the adapter to RX/TX pin of Serial, but this pins are wired on board to USB for communication with the computer (upload and Serial Monitor). You can't use Serial for RS485 adapter while you are using it for debug prints.
You can use SoftwareSerial fo example on D1/D2 for RS485.
Or if you have an USB-to-TTL-Serial adapter then you can use Serial1 for debug prints and Serial for RS485


text:
Change data-type String
I'm currently working with an ESP8266 NodeMCU V3 and an IR transmitter breakout board. The module receives NEC IR commands trough a HTTP request and then sends them trough the IR transmitter. Getting the command from the HTTP request and sending static (pre-programmed) IR NEC commands works perfectly. The problem however is that the NEC IR command I receive trough HTTP is in a String variable/data type (after processing). irsend.sendNEC(); however requires uint64_t as the input type, according to the error message I get in the Arduino IDE.
I don't really know my way around C data types to be honest. Searches like "Arduino String to uint64_t" have came up empty or reversed. One post came close to what I'm trying to accomplish, but irsend.sendNEC(strtoul(irrequest)); didn't do the trick either.
Arduino code;

Check for // Send IR NEC command almost at the bottom
The second and third irsend.sendNEC(); are an example and not in the final code
HTTP request is formatted like http://192.168.1.xxx/rest/ir/nec/0xFB0042BD

Sketch.ino

// Configuration
const char* CONFIG_SSID      = "mywifi";
const char* CONFIG_PSK       = "wifipassword";
const int   CONFIG_SERIAL    = 115200;
const int   CONFIG_PORT      = 80;
const int   CONFIG_TIMEOUT   = 5000;
const int   CONFIG_IRTPIN    = 2;

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

// Include libraries
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRutils.h>

// Create webserver object
WiFiServer server(CONFIG_PORT);

// Create IR Send object
IRsend irsend(CONFIG_IRTPIN);

// Setup instructions
void setup() {

  // Start serial and LED
  Serial.begin(CONFIG_SERIAL);
  Serial.println();
  Serial.println("Starting setup");
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, 1);

  // Start WiFi connection
  Serial.print("Connecting to: ");
  Serial.println(CONFIG_SSID);
  WiFi.mode(WIFI_STA);
  WiFi.begin(CONFIG_SSID, CONFIG_PSK);

  // Wait for WiFi connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("WiFi connected!");

  // Print WiFi connection information
  Serial.print("  SSID: ");
  Serial.println(WiFi.SSID());
  Serial.print("  RSSI: ");
  Serial.print(WiFi.RSSI());
  Serial.println(" dBm");
  Serial.print("  Local IP: ");
  Serial.println(WiFi.localIP());

  // Start webserver
  Serial.println("Starting webserver...");
  server.begin();
  delay(1000);
  Serial.println("Webserver started!");

  // Print webserver information
  Serial.print("  Host: ");
  Serial.println(WiFi.localIP());
  Serial.print("  Port: ");
  Serial.println(CONFIG_PORT);

  // Start IR Send
  Serial.println("Starting IR Send...");
  irsend.begin();
  delay(1000);
  Serial.println("IR Send started!");

  // Setup complete
  Serial.println("Setup completed");
  digitalWrite(LED_BUILTIN, 0);
  Serial.println();

}

// Loop instructions
void loop() {

  // Wait for new client
  WiFiClient client = server.available();
  if (client) {

    // New client
    digitalWrite(LED_BUILTIN, 1);
    Serial.println("New client connected");

    // Wait nicely for the client to complete its full request
    unsigned long timeout = millis() + CONFIG_TIMEOUT;
    Serial.println("Waiting for client request to finish...");
    while (!client.available() && millis() < timeout) {
      delay(1);
    }

    // End client connection when timeout is reached to not hold up availability
    if (millis() < timeout) {
      Serial.println("Client request finished!");
    } else {
      Serial.println("Client request timeout!");
      client.flush();
      client.stop();
      digitalWrite(LED_BUILTIN, 0);
      Serial.println();
      return;
    }

    // Catch client request
    String req = client.readStringUntil('\r');
    Serial.print("Request header: ");
    Serial.println(req);
    if (req.indexOf(F("/rest/ir/nec/")) != -1) {

      // Get IR Send NEC request
      String irrequest = req;
      irrequest.remove(0, ((irrequest.lastIndexOf("/rest/ir/nec/")) + 13));
      irrequest.remove((irrequest.indexOf(" ")));
      Serial.print("IR Send NEC code: ");
      Serial.println(irrequest);

      // Send IR NEC command
      Serial.println("Sending IR NEC command");
      irsend.sendNEC(irrequest);    // <<< here lays the problem
      irsend.sendNEC(0xFB0042BD);   // This works
      irsend.sendNEC("0xFB0042BD"); // This doesn't

      // Send HTTP response
      Serial.println("Sending HTTP/1.1 200 OK");
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/plain");
      client.println("Connection: close");
      client.println();
      client.println("OK");

    } else {

      // Invalid request
      Serial.println("Invalid client request");
      Serial.println("Sending HTTP/1.1 404 response");
      client.println("HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\nNot found");

    }

    // Flush output buffer
    Serial.println("Flushing output buffer");
    client.flush();
    digitalWrite(LED_BUILTIN, 0);
    Serial.println();
    return;

  }

}

irsend.sendNEC(strtoul(irrequest.c_str(), NULL, 10));  http://www.cplusplus.com/reference/cstdlib/strtoul/ https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/c_str/

irsend.sendNEC(strtoul(irrequest.c_str(), NULL, 10)); did the trick with the help of Juraj. Much thanks! I only had the set 10 to 16 to get it to work.
Working code:

// Configuration
const char* CONFIG_SSID      = "mywifi";
const char* CONFIG_PSK       = "wifipassword";
const int   CONFIG_SERIAL    = 115200;
const int   CONFIG_PORT      = 80;
const int   CONFIG_TIMEOUT   = 5000;
const int   CONFIG_IRTPIN    = 2;

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

// Include libraries
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRrecv.h>
#include <IRutils.h>

// Create webserver object
WiFiServer server(CONFIG_PORT);

// Create IR Send object
IRsend irsend(CONFIG_IRTPIN);

// Setup instructions
void setup() {

  // Start serial and LED
  Serial.begin(CONFIG_SERIAL);
  Serial.println();
  Serial.println("Starting setup");
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, 1);

  // Start WiFi connection
  Serial.print("Connecting to: ");
  Serial.println(CONFIG_SSID);
  WiFi.mode(WIFI_STA);
  WiFi.begin(CONFIG_SSID, CONFIG_PSK);

  // Wait for WiFi connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println();
  Serial.println("WiFi connected!");

  // Print WiFi connection information
  Serial.print("  SSID: ");
  Serial.println(WiFi.SSID());
  Serial.print("  RSSI: ");
  Serial.print(WiFi.RSSI());
  Serial.println(" dBm");
  Serial.print("  Local IP: ");
  Serial.println(WiFi.localIP());

  // Start webserver
  Serial.println("Starting webserver...");
  server.begin();
  delay(1000);
  Serial.println("Webserver started!");

  // Print webserver information
  Serial.print("  Host: ");
  Serial.println(WiFi.localIP());
  Serial.print("  Port: ");
  Serial.println(CONFIG_PORT);

  // Start IR Send
  Serial.println("Starting IR Send...");
  irsend.begin();
  delay(1000);
  Serial.println("IR Send started!");

  // Setup complete
  Serial.println("Setup completed");
  digitalWrite(LED_BUILTIN, 0);
  Serial.println();

}

// Loop instructions
void loop() {

  // Wait for new client
  WiFiClient client = server.available();
  if (client) {

    // New client
    digitalWrite(LED_BUILTIN, 1);
    Serial.println("New client connected");

    // Wait nicely for the client to complete its full request
    unsigned long timeout = millis() + CONFIG_TIMEOUT;
    Serial.println("Waiting for client request to finish...");
    while (!client.available() && millis() < timeout) {
      delay(1);
    }

    // End client connection when timeout is reached to not hold up availability
    if (millis() < timeout) {
      Serial.println("Client request finished!");
    } else {
      Serial.println("Client request timeout!");
      client.flush();
      client.stop();
      digitalWrite(LED_BUILTIN, 0);
      Serial.println();
      return;
    }

    // Catch client request
    String req = client.readStringUntil('\r');
    Serial.print("Request header: ");
    Serial.println(req);
    if (req.indexOf(F("/rest/ir/nec/")) != -1) {

      // Get IR Send NEC request
      String irrequest = req;
      irrequest.remove(0, ((irrequest.lastIndexOf("/rest/ir/nec/")) + 13));
      irrequest.remove((irrequest.indexOf(" ")));
      Serial.print("IR Send NEC code: ");
      Serial.println(irrequest);

      // Send IR NEC command
      Serial.println("Sending IR NEC command");
      irsend.sendNEC(strtoul(irrequest.c_str(), NULL, 16));

      // Send HTTP response
      Serial.println("Sending HTTP/1.1 200 OK");
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/plain");
      client.println("Connection: close");
      client.println();
      client.println("OK");

    } else {

      // Invalid request
      Serial.println("Invalid client request");
      Serial.println("Sending HTTP/1.1 404 response");
      client.println("HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\nNot found");

    }

    // Flush output buffer
    Serial.println("Flushing output buffer");
    client.flush();
    digitalWrite(LED_BUILTIN, 0);
    Serial.println();
    return;

  }

}


text:
Serial.read() always returns 255
So I'm trying to learn basic Android app dev. My master plan was to make an app using MIT App Inventor that would turn on an LED over Bluetooth using an Arduino. Once I verified that everything worked, I would write the entire app from scratch using Android Studio. This way, when I inevitably run into bugs with my written-from-scratch app, I could say with 100% certainty that the issue is in my Android code and not hardware/Arduino related.
So I'm having trouble right now. I have two separate LED circuits, a blue LED from port 13 and a green LED from pin 8. I verified that both circuits are working properly by using the Blink code, so I know the issue is definitely not with the LED circuits.
I'm using an HC 06 Bluetooth module. The pins are connected as follows:
HC 06 -> Arduino
RX -> TX
TX -> RX
5V -> 5V
GND -> GND
Here is the Arduino code:

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(0,1);
int ledblue = 13;
int ledgreen = 8;
int tx = 1;
int rx = 0;
int type;

void setup() {
  Serial.begin(9600);
  //bluetooth.begin(9600);
  pinMode(ledblue, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
  allpinslow();
}

void loop() {
  int i = 0;
  int m = 0;
  delay(500);
  if (Serial.available() > 0) {
    while(Serial.available() > 0){
      type = Serial.read();
      Serial.println(type);
    }
    Check_Protocol(type);
  }
}

void allpinslow()
{
  digitalWrite(ledgreen, LOW);
  digitalWrite(ledblue, LOW);
}

void Check_Protocol(int inStr) {
  int i = 0;
  int m = 0;
  if (inStr == '0') { //Led Off equals("2off")
    allpinslow();
  }
  if (inStr == '1') { //Led on
    digitalWrite(ledblue, HIGH);
  }
  if (inStr == '2'){
    digitalWrite(ledgreen,HIGH);
  }
}

Here is the MIT App Inventor block code

If I press the Green or Off button, the Serial Monitor spits out 255. If I press Red, nothing shows up on the serial monitor. I'm a bit dumbfounded on what is broken so I would greatly appreciate any help I can get.
Edit: @Delta_G here is the modified code
#include <SoftwareSerial.h>
int ledblue = 13;
int ledgreen = 8;
SoftwareSerial mySerial(2,4); //RX, TX
int type;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(ledblue, OUTPUT);
  pinMode(ledgreen, OUTPUT);
  allpinslow();
}

void loop() {
  int i = 0;
  int m = 0;
  delay(500);
  if (mySerial.available()) {
    while(mySerial.available()){
      type = mySerial.read();
      Serial.println(type);
    }
    Check_Protocol(type);
    //Serial.println(inSerial);
  }
}

void allpinslow()
{
  digitalWrite(ledblue, HIGH);
  digitalWrite(ledblue, LOW);
}

void Check_Protocol(int inStr) {
  int i = 0;
  int m = 0;
  if (inStr == '0') { //Led Off equals("2off")
    digitalWrite(ledblue, LOW);
    digitalWrite(ledgreen, LOW);
  }
  if (inStr == '1') { //Led on
    digitalWrite(ledblue, HIGH);
  }
  if (inStr == '2'){
    digitalWrite(ledgreen,HIGH);
  }
}

You have a big problem here: you are using both software and hardware serials at once. I suggest you to use only the hardware serial. To do so, remove the lines #include <SoftwareSerial.h> and SoftwareSerial bluetooth(0,1);. Then tell where is the serial terminal attached (to the arduino board?) and, finally, if it still doesn't work try swapping the RX and TX wires

The HC 06 RX pin is attached to pin 1, the HC 06 TX pin is attached to pin 0. I got rid of the two lines of code, but the same exact result still occur. Swapping the pins won't work-the phone will refuse to connect to the module

Apologies for the double comment - ". Then tell where is the serial terminal attached (to the arduino board?) " I set pin 0 (the Arduino's RX pin) to input and pin 1 (the Arduino's TX) pin to output - shouldn't this tell the Arduino where the serial terminal is attached?

Your code is referencing the "Serial" object which refers to the hardware UART, not the "bluetooth" object which is a softare serial instance on the now hopefully de-conflicted pins.

Hi, I attempted to use SoftwareSerial instead. I added the updated code to my original post. All three buttons on my app still return "255" in the serial monitor. If you could check the updated code out, I'd greatly appreciate it. Thanks!

Update: It was a faulty Bluetooth module that was causing the issues. I bought a new one and everything works perfectly!

From reading the comments, I assume you are using an Arduino Uno,
and you have a PC (or Mac, or any type of computer) connected to its USB
port, and an Android device at the other end of the Bluetooth link.
I can't see what is wrong with your sketch. I will then only suggest two
methods for checking the low-level communication is working properly.
Once you know the communication is good, debugging should be easier.
Test bypassing the microcontroller
First, load an empty sketch in the Arduino, then connect the
Bluetooth module as follows:
HC 06   Arduino
───────────────
 GND ─── GND
  5V ─── 5V
  RX ─── RX
  TX ─── TX

It is important to load the empty sketch first: you do not want the
Arduino to access its hardware serial port. Now you can open your serial
monitor on the PC, set to 9600/8N1.
With this setup, the HC 06 will be using the USB/serial bridge of the
Arduino (the ATmega16U2), whereas the main microcontroller (the
ATmega328P) is just a bystander. Whatever the HC 06 outputs through its
TX should appear on your serial monitor. The data path is as follows:
┌─────────┐  Bluetooth  ┌───────┐  Serial  ┌──────┐     ┌──────┐  USB  ┌────┐
│ Android │ ──────────→ │ HC 06 │ ───────┐ │ 328P │ ┌─→ │ 16U2 │ ────→ │ PC │
└─────────┘             └───────┘        │ └──────┘ │   └──────┘       └────┘
                                         └──────────┘

Note the 328P disconnected from the serial link.
Test with an echo sketch
Load the following sketch:
void setup()
{
    Serial.begin(9600);
}

void loop()
{
    if (Serial.available())
        Serial.write(Serial.read());
}

then connect the Bluetooth module as follows:
HC 06   Arduino
───────────────
 GND ─── GND
  5V ─── 5V
  RX ─── TX
  TX ─── RX

With this setup, whatever the HC 06 outputs on its TX should appear on
your serial monitor and should be sent back through Bluetooth. The
data path is:
┌─────────┐  Bluetooth  ┌───────┐  Serial  ┌──────┐     ┌──────┐  USB  ┌────┐
│ Android │ ──────────→ │ HC 06 │ ───────→ │ 328P │ ┌─→ │ 16U2 │ ────→ │ PC │
│         │ ←────────── │       │ ←──────┐ └──────┘ │   └──────┘       └────┘
└─────────┘             └───────┘        └─────┴────┘

Note that the output of the 328P is received by both the 16U2 and the
HC 06. Since the Android device seems to ignore whatever it receives
through Bluetooth, the setup should work fine for debugging you app too.

For the first method, I loaded an empty sketch, reconnected the HC 06, and opened the Serial Monitor in the IDE. Nothing happened. I connected to the HC 06 via Bluetooth on a second computer, opened TeraTerm VT, set it to 9600/8N1, tried pressing the buttons on the app. Nothing happened. None of the buttons I pressed elicited a response.
For the second method, I uploaded the echo sketch and opened the Serial Monitor again. This time, all I got was one backward question mark each time I pressed a button
http://imgur.com/a/I1qaP
Is it possible the module is faulty?

Then I would conclude that you have a communication problem upstream of the Arduino.

So it potentially could be a busted Bluetooth module?
The problem with the app is that this is a dummy app written in MIT App Inventor. There is no way for me to jump into the source code and verify that everything is actually correct. I essentially have to assume that the App Inventor compiled the app properly.

I cannot say, I do not know how the Bluetooth module is supposed to work, or how you can configure it. The experiment only proves it is not sending what you expect, so it's not your Arduino sketch that is faulty. If you have a scope, you could try to look at the module's TX when sending data from your app.

I used Step 2 from here to try and test my BT module:
https://create.arduino.cc/projecthub/mjrobot/connecting-stuff-via-bluetooth-android-arduino-d0b8f1
There was no response to any AT commands. Is this a possible indication of a DOA module?

I replaced Serial.write with Serial.println in your echo sketch, which returned 255. So... I guess we came back to the same place?

@theflyingoreo: Yes, but the sketch being now reduced to the bare minimum, you know the problem is not there. I would try looking at the module's TX with a scope, if you have one. Are you sure this module is talking at 9600/8N1? I have no experience with Bluetooth, so I am afraid I cannot provide more help.

If you are using Serial then you can't use pins 0 and 1 for something else as those are the hardware serialpins. Pick different pins for the Bluetooth.

If I use softwareserial and while attaching the HC 06 TX to pin 4 and HC 06 RX to pin 2, I get the same results (255)

255 is diagnostic.  That's what you'd get if you called read() when there is no data available.

But for the life of me I can't figure out why it's not getting any data. If you look at the app's block code, it is clearly sending 48, 49, and 50 yet the Arduino isn't getting anything

Show the new code with the new pins.  Who is doing the sending?  The bluetooth?  Are you reading the software serial instance?  Or are you just reading from Serial like in the code you posted?

I added the new code to my original post

And to answer your question, the app is supposed to send either 48, 49 or 50 to the Bluetooth module. The Bluetooth module then sends it to the Arduino, and depending on what value it got, it'll turn on one of the LEDs or turn them both off.

@Delta_G actually the value for no data available is -1; and the data types involved would appear to represent that correctly, rather than misinterpret it as 255, but perhaps you have a specific theory as to how that misinterpretation could arise?  Also note that the read only appears to be performed if a check for available data returns true.

Oh, I'm sorry.  I'm used to seeing people read into a 8bit variables.  I didn't realize this one actually read into an int.


text:
How to combine time into a variable
I have an Arduino Uno project which is recording student attendance using fingerprint sensor. So when sensor found a match, the serial monitor will be printing out Student ID and current time like this:
    DateTime now;
    void setup()
      {
          ...
      }

    void loop()
      {
          .....
          //found a match
          Serial.print("Found ID #");
          Serial.println(finger.fingerID);
          Serial.print("Time->");
          Serial.print(now.hour(), DEC);
          Serial.print(':');
          Serial.print(now.minute(), DEC);
          Serial.print(':');
          Serial.print(now.second(), DEC);
      }

Sample result will be:
Found ID#1
Time-> 18:11:54

I would like to store the time into a variable and print it out instead of printing hour, minute, and second separately. How can I do that???
I have tried to do like this as below but I'm getting an error, I would like to store it as a string. How can I do that?
string time = now.hour() + ':' + now.minute() + ':' + now.second();

It's going to be more efficient to print piece by piece. Because it constructs the text straight into the output buffer instead of needing to copy it over.

Hint: If you want to do some calculations or store a timestamp the data type time_t is a better choice. It is defined as seconds since midnight Jan 1 1970 (aka unix time). For more details see https://github.com/PaulStoffregen/Time/blob/master/TimeLib.h#L21

You want to use snprintf for this:
char timeString[9];

snprintf(timeString, 9, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
Serial.println(timeString);

By using a format string like this you are taking into account time portions < 10 (like 7 minutes and 23 seconds past 3 am, which would otherwise be 3:7:23) by padding the time with leading zeroes where needed.

Damn, you were three minutes quicker with the same solution.
Replacing 9 with sizeof timeString could be useful in case he ever wants to include more data into his time stamp.

Could be - as long as timeString is in the same (or greater) scope and not a pointer passed to a function :)

@Majenko Do you familiar with python or firebase? Cause I would like to send the output to the python code, for the python code itself will catch the output and push it to firebase real time database. I refer to this website , I made the output like this Serial.println("{'SID':"+ String(finger.fingerID) +",'time':"+ String(timeString) +"}"); but I don't know how to catch it in my python

I loathe python with a passion, and I have never heard of firebase.

@Majenko It's ok. I do the same thing to date. But I can display date like this2018/11/. Day cannot display, what happened?

Did you give enough room in your string?


text:
Arduino code issue (using Bluetooth and Rfid technology)
I am building a device that communicates with my Android phone.
I know that my App works but my Arduino code seems to have a problem.
So I have made a smaller programm and everything works fine there.
SMALLER PROGRAM - THAT WORKS

#include <SoftwareSerial.h>

SoftwareSerial btSerial(8,9); // RX, TX

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

void loop() {
  //Send everything from PC-Console
  while( Serial.available() )
  {
     btSerial.write( Serial.read() );
  }

  //Show everything received with bluetooth to PC-Console
  if(btSerial.available())
  {
    while(btSerial.available())
          Serial.write((char)btSerial.read());

    Serial.println("");
  }
}

I thought everything is fine so I've changed a few things in my original code.
But still the Arduino receives nothing, sending is no problem.
ORIGINAL PROGRAM - PROBLEM
#include <SoftwareSerial.h>

SoftwareSerial btSerial(8, 9); //RX TX
SoftwareSerial rfidSerial(11, 12);

char tagCollection4][13] = { {"6A003D68AA95"},
                             {"6A003D8879A6"},
                             {"6A003D49617F"},
                             {"6A003A426775"} };

String tagCollection_str[4] = {"6A003D68AA95",
                               "6A003D8879A6",
                               "6A003D49617F",
                               "6A003A426775"};

bool tagsFound[4] = {false, false, false, false};

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

void loop() {

 //Send everything from PC-Console to Bluetooth device | that part works
  while( Serial.available()  )
  {
    btSerial.write( Serial.read() );
  }

  //Show everything received with Bluetooth device on my PC-Console
  if( btSerial.available() )
  {
     while(btSerial.available())
              Serial.write((char)btSerial.read());

    Serial.println("");
  }

  //Here starts the Rfid Part that I’ve done first it works mostly
  char tagString[13];
  int index = 0;
  boolean reading = false;

  if(rfidSerial.available() )
  {
    while( rfidSerial.available() )
    {
      int readByte = rfidSerial.read(); //read next available byte

      if(readByte == 2) reading = true; //begining of tag
      if(readByte == 3) reading = false; //end of tag

      if(reading && readByte != 2 && readByte != 10 && readByte != 13){
        //store the tag
        tagString[index] = readByte;
        index ++;
      }
    }

    delay(50);
  }

  checkTag(tagString);
  clearTag(tagString); //Clear the char of all value
*/
}

void checkTag( char tag[] )
{
  if(strlen(tag) == 0) {return;}

  int tagNum = compareTag( tag );

  if( tagNum == -1 )
  {
    Serial.println("");
    Serial.println("NO MATCH");
    Serial.println("");
  }
  else
  {
   if( !tagsFound[tagNum] )
   {
      tagsFound[tagNum] = true;
   }
   else
   {
     tagsFound[tagNum] = false;
   }
   //Just a little delay
   delay(2000);
  }

  //Show the scanned tag
  Serial.println("");
  for( int i=0; i<13; i++ )
  {
   Serial.write(tag[i]);
  }

  Serial.println("");

  for(int i=0; i<4; i++)
  {
      Serial.println( tagsFound[i] );
  }

  Serial.println("");
  Serial.println("");

}

int compareTag( String tag )
{

  if(tag[9] == tagCollection4[0][9])
      return 0;

  if(tag[9] == tagCollection4[1][9])
      return 1;

 if(tag[9] == tagCollection4[2][9])
      return 2;

  if(tag[9] == tagCollection4[3][9])
      return 3;

  return -1;
}

void clearTag(char one[]){
///////////////////////////////////
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}

Please help me, it's for a school project.
Thanks for everything in advance.

So, what doesn't work?

With the original code I can't receive anytging over bluetooth

Is that "The phone doesn't receive anything transmitted by the Arduino over bluetooth", or "The Arduino doesn't receive anything transmitted by the phone over bluetooth"?  You have to be explicit in what you tell us, we can't guess your meanings since we haven't seen your system not working like you have.

sry, sry the arduino doesn't receive anything

possible duplicate of SoftwareSerial problems


text:
Arduino Serial Monitor shows strange ASCII characters
I connected an ArduiMU v3+ via a FTDI-cable to my Mac (OS X 10.10) (latest VC FTDI driver is installed and loaded).
Inside the Arduino-software the Serial Monitor (monitoring /dev/cu.usbserial-AJ038NZ3) shows
a lot of weird ASCII characters.
What could be the reason for this problem?

Here's part of the code I uploaded to the ArduiMu:

void setup() {

// Init Serial for use by Send.cpp and Receive.cpp
Serial.begin(115200);

}

void loop() {
    Receive::doTasks();
}

    void Send::flexSensorData() {
    char packet[64];
    int packetLength = 0;
    IntUnion intUnion;
    FlexSensors::read();    // read sensors before sending
#ifdef BINARY_PACKETS
    packet[packetLength++] = 'F';
    intUnion.intVal= (int)FlexSensors::channel[0];
    packet[packetLength++] = intUnion.msb;
    packet[packetLength++] = intUnion.lsb;
    intUnion.intVal= (int)FlexSensors::channel[1];
    packet[packetLength++] = intUnion.msb;
    packet[packetLength++] = intUnion.lsb;
    intUnion.intVal= (int)FlexSensors::channel[2];
    packet[packetLength++] = intUnion.msb;
    packet[packetLength++] = intUnion.lsb;
    intUnion.intVal= (int)FlexSensors::channel[3];
    packet[packetLength++] = intUnion.msb;
    packet[packetLength++] = intUnion.lsb;
    intUnion.intVal= (int)FlexSensors::channel[4];
    packet[packetLength++] = intUnion.msb;
    packet[packetLength++] = intUnion.lsb;
    intUnion.intVal= (int)FlexSensors::channel[5];
    packet[packetLength++] = intUnion.msb;
    packet[packetLength++] = intUnion.lsb;
    packet[packetLength++] = calcChecksum(packet, packetLength);
#else
    packet[packetLength++] = 'F';
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, (int)FlexSensors::channel[0]);
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, (int)FlexSensors::channel[1]);
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, (int)FlexSensors::channel[2]);
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, (int)FlexSensors::channel[3]);
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, (int)FlexSensors::channel[4]);
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, (int)FlexSensors::channel[5]);
    packet[packetLength++] = ',';
    IntValToChars(packet, &packetLength, calcChecksum(packet, packetLength));
    packet[packetLength++] = '\r';
#endif
    Serial.write((uint8_t*)packet, packetLength);
}

You're sending non-ASCII data.

Or a wrong Baud rate is set.

I tried all baud-rates. It is always the same.

You only need to try one: the one you gave to Serial.begin().

I added to code I've loaded on the Arduino to the initial question.

This code is not sending anything through the serial port.

@EdgarBonet Oops, exchanged it for one of the write-function. They all use Serial.write((uint8_t*)packet, packetLength);

As already said, you are sending binary data so what you receive is (probably) right. Try to send "Hello world" and see if it works.

The code you posted is incomplete; there is no evidence here that Send::flexSensorData() is called. Also, since your code includes conditional compilation, you should indicate the value of BINARY_PACKETS so we don't try to guess it from your code...


text:
Problem in Uploading through Visual Studio
This is my simple program:

int led = 13;
void setup()
{
    pinMode(led, OUTPUT);
  /* add setup code here */

}

void loop()
{
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
  /* add main program code here */

}

I tried to upload it using Visual Studio 2013 using a plugin Visual Micro for Arduino. But it resulted in this error:

Compiling 'bb' for 'Intel® Galileo Gen2'
Binary sketch size: 83,455 bytes (used 1% of a 10,000,000 byte maximum) (0.17 secs)
Compiling debug version of 'bb' for 'Intel® Galileo Gen2'
Binary sketch size: 85,056 bytes (used 1% of a 10,000,000 byte maximum) (2.81 secs)
Uploading to I/O board using 'COM3'
starting download script
Args to shell: C:\arduino-1.5.3-Intel.1.0.4/hardware/tools/x86/bin C:\Users\Shiran Abbasi\AppData\Local\V.Micro\Arduino\Builds\bb\izmir_fg/bb.elf COM3
COM PORT Abbasi\AppData\Local\V.Micro\Arduino\Builds\bb\izmir_fg/bb.elf
Converted COM Port Abbasi\AppData\Local\V.Micro\Arduino\Builds\bb\izmir_fg/bb.elf to tty port
Sending Command String to move to download if not already in download mode
Deleting existing sketch on target
Moving downloaded file to /sketch/sketch.elf on target

#!/bin/sh

echo "starting download script"
echo "Args to shell:" $*

# ARG 1: Path to lsz executable.
# ARG 2: Elf File to download
# ARG 3: COM port to use.

#path contains \ need to change all to /
path_to_exe=$1
fixed_path=${path_to_exe//\\/\/}

#COM ports are not always setup to be addressed via COM for redirect.
#/dev/ttySx are present. Howwever, COMy -> /dev/ttySx where x = y - 1

com_port_arg=$3
com_port_id=${com_port_arg/COM/}
echo "COM PORT" $com_port_id
tty_port_id=/dev/ttyS$((com_port_id-1))
C:\arduino-1.5.3-Intel.1.0.4/hardware/arduino/x86/tools/izmir/clupload_win.sh: line 20: Abbasi\AppData\Local\V.Micro\Arduino\Builds\bb\izmir_fg/bb.elf: syntax error: invalid arithmetic operator (error token is "\AppData\Local\V.Micro\Arduino\Builds\bb\izmir_fg/bb.elf")
echo "Converted COM Port" $com_port_arg "to tty port" $tty_port_id

echo "Sending Command String to move to download if not already in download mode"
echo "~sketch download" > $tty_port_id
C:\arduino-1.5.3-Intel.1.0.4/hardware/arduino/x86/tools/izmir/clupload_win.sh: line 24: $tty_port_id: ambiguous redirect

#Move the existing sketch on target.
echo "Deleting existing sketch on target"
$fixed_path/lsz.exe --escape -c "mv -f /sketch/sketch.elf /sketch/sketch.elf.old"  $tty_port_id 1>&0
C:\arduino-1.5.3-Intel.1.0.4/hardware/arduino/x86/tools/izmir/clupload_win.sh: line 28: $tty_port_id: ambiguous redirect

# Execute the target download command

#Download the file.
host_file_name=$2
$fixed_path/lsz.exe --escape --binary --overwrite $host_file_name  $tty_port_id 1>&0
C:\arduino-1.5.3-Intel.1.0.4/hardware/arduino/x86/tools/izmir/clupload_win.sh: line 34: $tty_port_id: ambiguous redirect

#mv the downloaded file to /sketch/sketch.elf
target_download_name="${host_file_name##*/}"
echo "Moving downloaded file to /sketch/sketch.elf on target"
#$fixed_path/lsz.exe --escape -c "cp sketch /sketch/sketch.elf"  $tty_port_id 1>&0
$fixed_path/lsz.exe --escape -c "mv $target_download_name /sketch/sketch.elf; chmod +x /sketch/sketch.elf"  $tty_port_id 1>&0
C:\arduino-1.5.3-Intel.1.0.4/hardware/arduino/x86/tools/izmir/clupload_win.sh: line 40: $tty_port_id: ambiguous redirect

Any help would be appreciated.

I see nothing that looks like an error in the output you posted. Is that all you got?

yeah it's all i got and it's very annoying because when i upload the same program using arduino ide, it gets uploaded successfully.

@jfpoilpret can u help me?

I'm afraid I can't help as I think we are all lacking information here. First how do you know the upload went badly since there is no real error message? What I find strange in the output you psoeted is the shell script that has nothing to do here since you are on Windows...

You have to keep Visual Micro up to date when using new Ide's. The intel Ide functionality was evolving but has now been moved to the Arduino 1.6.2+ boards manager. Again, with the latest Visual Micro releases it is supported