Sending data from Arduino to PC via ethernet shield

Hi guys,
I have worked with arduino for 2 days but still reason. I have following problem.

Arduino SW:

#include <SPI.h>
#include <Ethernet.h>

String tem,temper;
long cas=0;
char buffer[5]={" "};
float t=2.2;

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,10,18);
IPAddress gateway(192,168,10,17);
IPAddress subnet(255,255,255,252);

EthernetServer server(2000);
boolean alreadyConnected = false;

void setup()
{
Ethernet.begin(mac, ip, gateway, subnet);
}

void loop()
{
EthernetClient client = server.available();
if ( millis() >= cas) {
t=t+1.2;
tem=dtostrf(t,5,1,buffer);
temper=(tem);
client.print(temper);
cas=cas+5000;
}
}

In PC I have SW programmed in C++ in Borland studio. In this programme I want to send data, especially float number via function client.print()...via ethernet shield to PC. Client.print() cannot send float so I need change it into string, it does dtostrf() function. I have connection with PCs and ping be successfull.

C++ SW:

void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
Memo1->Lines->Clear();
Teplota=ClientSocket1->Socket->ReceiveText();
Memo1->Lines->Add(Teplota);
}

Here is my outputs:

Screenshot by Lightshot //after a few seconds x*sec it was 13 (it is ok)
Screenshot by Lightshot // after next 20 sec it should be 17.8, but I saw only xx.8
Screenshot by Lightshot // aftert next 20 sec it should be 22,6, but I saw only x2.6
Screenshot by Lightshot // and endly after next 20 sec it should be 28,6, but was only x8,6

This is to say that sometimes I just do not display the full value of its cast. I think that, some bits were passed over.

Any solution?...maybe try to use UDP connection?...Thanks a lot

You have two errors.
One, the call to Ethernet.begin() is not correct. You are missing the dns server ip. I used the gateway below.
Two, you never start the server. Call server.begin() in the setup function.

void setup() 
 {
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, gateway,subnet);
  Serial.println(Ethernet.localIP());
  server.begin();
 }

I will try but I dont have trouble with connection, or can this make a trouble with sending information?

If you are using an Ethernet client function thru a router, you don't need a lot of network setup info in your code. below is simple client test code you can try to see if it works with your LAN network setup.

//zoomkat 9-22-12
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//remove SD card if inserted

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("Better client test 9/22/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET /~shb/arduino.txt HTTP/1.1"); //download text
    client.println("Host: web.comporium.net");
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

If you don't set up the w5100 correctly, and don't start the server, then expect it to work right, you may be expecting too much.
If all else fails...follow the directions.

If you are looking for rapid data transfer, think about UDP. I've gotten some good results using that protocol.

In this way I only use point-to-point connection, so Arduino attached directly to notebook via Ethernet cable, I dont need to send a huge data only to send a data/information from temperature senzor, which library return float number and I need do conversion to string and send it. But I check, that there are some trouble, sometimes all is good all data arrived, and sometimes only last 1 number, but this is not a huge information only 4 digits 12.2...

I would use UDP for that. I do already. I have Linux UDP code for the PC, and the Arduino UDP test code here. I use a 48 byte packet. That will send a lot of data.

It works like a server-client deal. The Arduino "client" sends a packet to the PC "server" (listener) and the server immediately returns a packet to the client. It had no trouble at 30 packets/second. That is all I needed.

edit: If you are interested, I will post it here.

I found a something about UDP, but yes I am interested I will thank you for it :slight_smile:

Here is the Arduino code. I have it slowed down to one packet per second so you can see it work. You can speed it up by changing the msPerSecond value.

#include <SPI.h>         
#include <Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress ip(192,168,2,2);
IPAddress gateway(192,168,2,1);
IPAddress subnet(255,255,255,0);

unsigned int UDPport = 5005;      // local port to listen for UDP packets

//  Change to your PC IP
IPAddress UDPServer(1,2,3,4); //Your UDP server

const int UDP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[ UDP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 

unsigned int noChange = 0;

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

unsigned long currentTime;
unsigned long secondTime;

unsigned long msPerSecond = 1000UL;

int UDPCount = 0;

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

  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  // start Ethernet and UDP
  Serial.print(F("Starting w5100..."));
//  Ethernet.begin(mac,ip,gateway,gateway,subnet);

  while(!Ethernet.begin(mac)) {
    Serial.println(F("failed. Retrying in 5 seconds."));
    delay(5000);
    Serial.print(F("Starting w5100..."));
  }

  Serial.println(Ethernet.localIP());
  
  Udp.begin(UDPport);

  delay(2000);

  currentTime=millis();
  secondTime = currentTime;
  
  Serial.println("Ready");
}



void loop()
{
  currentTime = millis();

  getUDPpacket();


  if(currentTime - secondTime > msPerSecond) {
      byte rtnVal = Ethernet.maintain();
      switch(rtnVal) {
        case 1: Serial.println(F("\r\nDHCP renew fail"));        
                break;
        case 2: Serial.println(F("\r\nDHCP renew ok"));        
                break;
        case 3: Serial.println(F("\r\nDHCP rebind fail"));        
                break;
        case 4: Serial.println(F("\r\nDHCP rebind ok"));        
                break;
                
      }
      
          
      Serial.println(F("\r\nUDP send"));
      sendUDPpacket(UDPServer); // send an NTP packet to a time server
      secondTime += msPerSecond;
  }
}

unsigned int udpCount = 0;

// send an UDP request to the UDP server at the given address 
unsigned long sendUDPpacket(IPAddress& address)
{
  udpCount++;
  
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, UDP_PACKET_SIZE); 


  sprintf((char*)packetBuffer,"Arduino count %u",udpCount);

  Udp.beginPacket(address, UDPport); // Requests are to port 5005
  Udp.write(packetBuffer,UDP_PACKET_SIZE);
  Udp.endPacket(); 
}


void getUDPpacket() {
  if ( Udp.parsePacket() ) {  
    // We've received a packet, read the data from it

    if(Udp.remoteIP() == UDPServer) {
      Serial.print(F("UDP IP OK  "));
    }
    else {
      Serial.println(F("UDP IP Bad"));
      return;
    }
    if(Udp.remotePort() == UDPport) {
      Serial.println(F("Port OK"));
    }
    else {
      Serial.println(F("Port Bad"));
      return;
    }

    Udp.read(packetBuffer,UDP_PACKET_SIZE);  // read the packet into the buffer

    Serial.print(F("Received: "));
    Serial.println((char*)packetBuffer);
  }
}

edit: Here is the PC linux C code. I had to get into the "server" to get this code. Remember to open port 5005/udp on the PC "server" firewall or it will fail.

#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int sock, n, nr;
    socklen_t fromlen;
    struct sockaddr_in server;
    struct sockaddr_in from;
    
    sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0)
     printf("Can not create socket in server\n");
 
    memset(&server, 0, sizeof(struct sockaddr_in));
    server.sin_family = AF_INET;
    server.sin_port = htons(5005);
    server.sin_addr.s_addr = INADDR_ANY;
 
    if(bind(sock, (struct sockaddr *)&server, sizeof(server)) < 0)
      printf("Can not bind in server!\n");
    memset(&from, 0, sizeof(struct sockaddr_in));
    fromlen = sizeof(struct sockaddr_in);
    
    
    while(1) {
        int n, l1;
	unsigned char tBuf[48];
	unsigned char outBuf[48];
	
	
	fflush(stdout);

	n = recvfrom(sock, tBuf, sizeof(tBuf), 0, (struct sockaddr*) &from, &fromlen);
        if (n < 0) {
            printf("Can not receive in server!\n");
        }

	printf("%s from IP:%s, Port:%hu\r\n",&tBuf[0],inet_ntoa(from.sin_addr), ntohs(from.sin_port));

	sprintf(outBuf,"Server: %s\0",tBuf);
	socklen_t length = sizeof(struct sockaddr_in);	

	n = sendto(sock, outBuf, 48, 0, (const struct sockaddr *)&from, fromlen);
	if(n < 0) {
	  printf("Can not send from client");
	}
    }
}

I saved this code as udpserver.c in my C directory.

cd C
cc udpserver.c -o udpserver.exe
./udpserver.exe

I will test it with my data and after it I will post my reaction, so on thanks for this time.

I just tested the udp sketch adapted for a wifi shield with the Linux code on a Raspberry Pi, and it runs great! :slight_smile:

Can someone walk me through the linux side of SurferTims code example? I loaded the arduino code onto an arduino uno with an Ethernet shield. I am using a raspberry pi2 for the linux, when i saved the code using Geany I got the following errors

g++ -Wall -o "Server" "Server.cpp" (in directory: /home/pi/Desktop)
Server.cpp: In function ‘int main()’:
Server.cpp:45:36: error: invalid conversion from ‘unsigned char*’ to ‘char*’ [-fpermissive]
  sprintf(outBuf,"Server: %s\0",tBuf);
                                    ^
In file included from Server.cpp:5:0:
/usr/include/stdio.h:364:12: note: initializing argument 1 of ‘int sprintf(char*, const char*, ...)’
 extern int sprintf (char *__restrict __s,
            ^
Server.cpp:45:36: warning: embedded ‘\0’ in format [-Wformat-contains-nul]
  sprintf(outBuf,"Server: %s\0",tBuf);
                                    ^
Server.cpp:31:15: warning: unused variable ‘l1’ [-Wunused-variable]
        int n, l1;
               ^
Server.cpp:46:12: warning: unused variable ‘length’ [-Wunused-variable]
  socklen_t length = sizeof(struct sockaddr_in);
            ^
Server.cpp:10:14: warning: unused variable ‘n’ [-Wunused-variable]
    int sock, n, nr;
              ^
Server.cpp:10:17: warning: unused variable ‘nr’ [-Wunused-variable]
    int sock, n, nr;
                 ^
Compilation failed.

I then saved the file using

sudo nano udpserver.exe

but when i try to call on it this is what it says

pi@raspberrypi ~ $ gcc -Wall -o udpserver udpserver.exe
udpserver.exe: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status

What am I doing wrong? When I saved it as .c instead of .exe it gave me the same errors that I got when I tried to compile it using Geany

Thomas499:
Can someone walk me through the linux side of SurferTims code example? I loaded the arduino code onto an arduino uno with an Ethernet shield. I am using a raspberry pi2 for the linux, when i saved the code using Geany I got the following errors

g++ -Wall -o "Server" "Server.cpp" (in directory: /home/pi/Desktop)

Server.cpp: In function ‘int main()’:
Server.cpp:45:36: error: invalid conversion from ‘unsigned char*’ to ‘char*’ [-fpermissive]
  sprintf(outBuf,"Server: %s\0",tBuf);
                                    ^
In file included from Server.cpp:5:0:
/usr/include/stdio.h:364:12: note: initializing argument 1 of ‘int sprintf(char*, const char*, ...)’
extern int sprintf (char *__restrict __s,
            ^
...
Compilation failed.





I then saved the file using but when i try to call on it this is what it says What am I doing wrong? When I saved it as .c instead of .exe it gave me the same errors that I got when I tried to compile it using Geany

I just tried
gcc -Wall udpserver.c -o udpserver
udpserver.c: In function ‘main’:
udpserver.c:44:2: warning: pointer targets in passing argument 1 of ‘sprintf’ differ in signedness [-Wpointer-sign]
/usr/include/stdio.h:361:12: note: expected ‘char * restrict’ but argument is of type ‘unsigned char *’
udpserver.c:44:2: warning: embedded ‘\0’ in format [-Wformat-contains-nul]
udpserver.c:45:12: warning: unused variable ‘length’ [-Wunused-variable]
udpserver.c:30:15: warning: unused variable ‘l1’ [-Wunused-variable]
udpserver.c:9:17: warning: unused variable ‘nr’ [-Wunused-variable]
udpserver.c:9:14: warning: unused variable ‘n’ [-Wunused-variable]

I changed
unsigned char outBuf[48];
to
char outBuf[48];

and there were "only" warnings left:
gcc -Wall udpserver.c -o udpserver
udpserver.c: In function ‘main’:
udpserver.c:44:2: warning: embedded ‘\0’ in format [-Wformat-contains-nul]
udpserver.c:45:12: warning: unused variable ‘length’ [-Wunused-variable]
udpserver.c:30:15: warning: unused variable ‘l1’ [-Wunused-variable]
udpserver.c:9:17: warning: unused variable ‘nr’ [-Wunused-variable]
udpserver.c:9:14: warning: unused variable ‘n’ [-Wunused-variable]

The unused parts are simple.
socklen_t length = sizeof(struct sockaddr_in); is not needed since there is
fromlen = sizeof(struct sockaddr_in);

gcc -Wall -o udpserver udpserver.exe -> you don't need that udpserver.exe at the end
since the excutable program in Linux does not need an ".exe" at the end.
if you do
ls -l udpserver
you will see the executable:
-rwxr-xr-x 1 pi pi 7044 Nov 9 23:59 udpserver
See also: Linux.com - News For Open Source Professionals
To get this program running do a
$ ./udpserver
This will start the program but occupy the terminal.
To start in background do
$ ./udpserver &
To see all running jobs:
$ jobs
[2]- Running leafpad udpserver.c &
[3]+ Running ./udpserver &

Best regards

Thanks MEgg, with that information, I was able to get the program running correctly.

I do have three more questions,

1:
If the power goes out, the arduino reboots and the arduino side goes back to normal. However, the raspberry which runs the linux will not go back to the same program unless you type in

$ ./udpserver &

again... and you may need to type in

gcc -Wall udpserver.c -o udpserver

again too, i'm really not sure.

Anyway, is there a way to write the linux side so that it starts automatically, so if the power does go out for a few seconds, it will pull the program back up without having to retype the commands in?

2:
Arduino seems to be written in a different form of C++ than the linux uses. I'm assuming that's because the IDE simplifies the code to make life much easier. I do like that, but is there a way to get the offical C++ code from the IDE so I can use the C++ code that I am use to using on arduino on the linux side?

3:
I know this is going to sound silly, but can someone show me how to send information that tells the linux side which booleans are active? The example shows how to send 1 int, or maybe a long int, but lets say you wanted to send information that tells the linux side to do something, but you had multiple booleans that needed to be sent. How would you tell the linux side to identify the different booleans?

Anyway, is there a way to write the linux side so that it starts automatically, so if the power does go out for a few seconds, it will pull the program back up without having to retype the commands in?

The linux side being the raspberry pi? This is the Arduino forum. The pi place is down the street a ways.

Arduino seems to be written in a different form of C++ than the linux uses.

No. If you have some specific example(s) that you'd like to discuss, feel free. "It seems..." is useless speculation.

I know this is going to sound silly, but can someone show me how to send information that tells the linux side which booleans are active?

What does "active" mean? A boolean variable is active when it is in scope. It might contain true. It might contain false. But, it is always active.

Arduino seems to be written in a different form of C++ than the linux uses.

No. If you have some specific example(s) that you'd like to discuss, feel free. "It seems..." is useless speculation.

Alright, so I decided I wanted to use an external editor so I could use features like... the thing that excel also has where it draws a line to the right, and has a + and - sign on the top and bottom of the line, and you can click the line so that it hides part of the code that you know works well, that way its easier to find the parts you are debugging quicker.

Anyway, I downloaded Geany because it seems to be popular, and works in linux and windows. I created a new file, then went to document, set fileType, programming languages, and selected C++

Using what I learned working with arduino, I entered the following code which I thought was C++ standard

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
boolean Switcher = LOW;             // ledState used to set the LED

const int interval = 1000;           // interval at which to blink (milliseconds)

void setup() 
{
  
}

void loop() 
{
	if (Switcher==LOW)
	printf(F("Hello world!"));
	else
	printf(F("Wait for it..."));
    delay(interval);
    printf(interval);
    printfln(); // start new line
}

but I got these errors,

g++ -Wall -o "Helloworld" "Helloworld.cpp" (in directory: /home/pi/Desktop)
Helloworld.cpp:5:1: error: ‘boolean’ does not name a type
 boolean Switcher = LOW;             // ledState used to set the LED
 ^
Helloworld.cpp: In function ‘void loop()’:
Helloworld.cpp:16:6: error: ‘Switcher’ was not declared in this scope
  if (Switcher==LOW)
      ^
Helloworld.cpp:16:16: error: ‘LOW’ was not declared in this scope
  if (Switcher==LOW)
                ^
Helloworld.cpp:17:25: error: ‘F’ was not declared in this scope
  printf(F("Hello world!"));
                         ^
Helloworld.cpp:19:27: error: ‘F’ was not declared in this scope
  printf(F("Wait for it..."));
                           ^
Helloworld.cpp:20:19: error: ‘delay’ was not declared in this scope
     delay(interval);
                   ^
Helloworld.cpp:21:20: error: invalid conversion from ‘int’ to ‘const char*’ [-fpermissive]
     printf(interval);
                    ^
In file included from Helloworld.cpp:2:0:
/usr/include/stdio.h:362:12: note: initializing argument 1 of ‘int printf(const char*, ...)’
 extern int printf (const char *__restrict __format, ...);
            ^
Helloworld.cpp:22:14: error: ‘printfln’ was not declared in this scope
     printfln(); // start new line
              ^
Compilation failed.

i understand somethings like Serial.print and millis() may be specifically for arduino, but that doesn't explain the mass of errors if arduino uses universal C++ the arduino IDE has to be the reason arduino is simpler, but is it possible to get the C++ standard code that the arduino IDE writes when it complies the program?

What does "active" mean? A boolean variable is active when it is in scope. It might contain true. It might contain false. But, it is always active.

I think of booleans as active high, or active low. when I said active, I wanted to transfer the high or low status of multiple booleans wirelessly.

the thing that excel also has where it draws a line to the right, and has a + and - sign on the top and bottom of the line, and you can click the line so that it hides part of the code that you know works well, that way its easier to find the parts you are debugging quicker.

That's called code folding, and is a really useful feature OF THE TEXT EDITOR. It has NOTHING to do with the programming language. Visual Studio does that nicely for C, C++, C#, FORTRAN, etc. Notepad++ does it for all those languages, too.

Anyway, I downloaded Geany because...I entered the following code which I thought was C++ standard...but I got these errors,

How did you try to compile that code? Certainly not using the IDE. When I did, I got:

sketch_nov12a.ino: In function 'void loop()':
sketch_nov12a:17: error: cannot convert 'const __FlashStringHelper*' to 'const char*' for argument '1' to 'int printf(const char*, ...)'
sketch_nov12a:19: error: cannot convert 'const __FlashStringHelper*' to 'const char*' for argument '1' to 'int printf(const char*, ...)'
sketch_nov12a:21: error: invalid conversion from 'int' to 'const char*'
sketch_nov12a:21: error: initializing argument 1 of 'int printf(const char*, ...)'
sketch_nov12a:22: error: 'printfln' was not declared in this scope

printf() is a standard C function. But, where does it print? To the console window. Have you LOOKED at your Arduino? Get it out. Take a peek. Take a picture. Post it here, with the console window circled, please.

You can't reasonably expect a standard C function to have an overload that deals with non-standard extensions, like the F() macro.

For that matter, why did you ASSume that F() was standard C/C++?

And, what the f**k if printfln()? Can you cite a link to ANY C book that contains that function?

I think of booleans as active high, or active low.

That's nonsense. Booleans are true or false.

when I said active, I wanted to transfer the high or low status of multiple booleans wirelessly.

So, what it stopping you?

That's called code folding, and is a really useful feature OF THE TEXT EDITOR. It has NOTHING to do with the programming language. Visual Studio does that nicely for C, C++, C#, FORTRAN, etc. Notepad++ does it for all those languages, too.

that's why I said

so I decided I wanted to use an external editor so I could use features like

I wasn't implying that I thought that had to do with the C++ language. As I said I needed a text editor that worked in Linux and windows that's why I went with Geany instead of Notepad++

How did you try to compile that code? Certainly not using the IDE. When I did, I got:

No, I complied it using Geany's compiler. The reason is, I need arduino and a computer to work together, so the program needs to work in Linux. The reason for this is, so I can stream sound that will work with the arduino program. There isn't anything available that I could find that allows sound to be streamed using arduino. There are sound modules, but you have to take the sd card out to load the sound files, you can't even load them wirelessly directly to the sd card without taking it out and inserting it into a computer. Using a computer, the computer has enough processing power and the hardware needed to stream. The IDE isn't designed to put the code in a Linux file that isn't directly attached to an arduino... or if it can, that would be great!

printf() is a standard C function. But, where does it print?

On the computer monitor. I am trying to take out parts of the code I wrote for arduino, such as which sound files to play, and the wifi server part (if you load the simple wifi server code that comes pre-loaded on the arduino example library and call the server section, the arduino will work correctly for 6 minutes once called, then it will freeze and become unresponsive. There is no reason that I can find that causes this) the computer doesn't have that problem when used as a server. I would like to be able to use the code I wrote for the arduino on the computer. I am using the computers command prompt version on linux to print so I can see what is going on.

You can't reasonably expect a standard C function to have an overload that deals with non-standard extensions, like the F() macro.

For that matter, why did you ASSume that F() was standard C/C++?

That's why I am trying to find a way to get the official C++ code that arduino writes from the IDE so I can use all the things that I am use to. For example, why is boolean on arduino bool on everything else? I have code that is over 160,000 bytes I would prefer not to have to start from scratch trying to transfer it to the computer.

Random question, does the F() use Strings to work that are harsh on memory management?

When I add F() here

if (PaulSsaysEndswithNotUsingStrings(F("GET /H")))
Serial.println(F("LED ON"));

I get this error

SimpleWebServerWiFi8:136: error: cannot convert 'const __FlashStringHelper*' to 'char*' for argument '1' to 'boolean PaulSsaysEndswithNotUsingStrings(char*)'

which refers to the F() as FlashStringHelper

And, what the f**k if printfln()? Can you cite a link to ANY C book that contains that function?

is there a universal way to print in C++ that adds a line-break to the end without typing in '/n' at the end of the thing to print? Like Serial.println automatically line breaks at the end?

That's nonsense. Booleans are true or false.

In arduino, I was taught you could use boolean=1; boolean =HIGH; or boolean=TRUE; watch 8:25-8:32 for the demo I watched when I was learning how to program the arduino.

So, what it stopping you?

converting the code I wrote for arduino so that it will work on a computer. Is there a folder the IDE writes the code to that is standard C++ that I can copy and transfer to a computer that will allow the code that was originally written for arduino will transfer to work on the computer? (for example on arduino I sometimes wrote boolean switch=0; where the computer expects bool switch = true)

No, I complied it using Geany's compiler. The reason is, I need arduino and a computer to work together, so the program needs to work in Linux.

So, you expected Geany's compiler to build HEX files for the Arduino. Interesting concept. Not one that is going anywhere, but interesting nonetheless.

The reason for this is, so I can stream sound that will work with the arduino program.

Sound in what format, from where to where? How do you expect sound to "work with the Arduino program"? What does that even mean?

The IDE isn't designed to put the code in a Linux file that isn't directly attached to an arduino

I don't understand this statement. The IDE can store the source code in a file, on any operating system. There are no Linux files directly attached to the Arduino. This whole statement doesn't make sense.

For example, why is boolean on arduino bool on everything else?

bool is the standard. Works on the Arduino, too. boolean is a non-standard extension that works only on the Arduino. Use the standard.

Random question, does the F() use Strings to work that are harsh on memory management?

No. The F() macro prevents copying the string literal from flash memory to SRAM. No Strings involved.

When I add F() here

Yes, because the function needs to understand that the argument is NOT going to be a character string. It is going to be something else that wraps a string literal.

is there a universal way to print in C++ that adds a line-break to the end without typing in '/n' at the end of the thing to print?

The standard in C++ is cout, but that writes to the console, the same as printf() does. The Arduino doesn't have a console, so cout and printf() are out.

Serial.print() and/or Serial.println() do what people normally use cout/printf() for.

In arduino, I was taught you could use boolean=1; boolean =HIGH; or boolean=TRUE

While 1, HIGH, and true are all the same value, the context in which each is used is different. Effective communication means paying attention to context. YMMV.

Is there a folder the IDE writes the code to that is standard C++ that I can copy and transfer to a computer that will allow the code that was originally written for arduino will transfer to work on the computer?

The sketch IS standard C++. That there are a lot of classes that are specific to the Arduino, and a completely different use of memory, which is in very limited supply on the Arduino, is what makes taking a program written for the Arduino just about unusable anywhere else.

The paradigm IS portable, and not that difficult to implement on a PC with tons of memory, a console, a file system, and an operating system. The converse (taking a PC program and fitting it onto the Arduino) is not necessarily easy or possible.

So, you expected Geany's compiler to build HEX files for the Arduino. Interesting concept. Not one that is going anywhere, but interesting nonetheless.

No, i expect the Geany compiler to build the files that will work on Linux. To work on the arduino I would use the arduino's IDE and go to file, preferences, and use external editor. That would work wouldn't it?

Sound in what format, from where to where? How do you expect sound to "work with the Arduino program"? What does that even mean?

What format? with the arduino the files are currently in AD4 format. But because I want to be able to upload new sound files wirelessly, and stream music and stuff using the same speaker system I want the arduino to tell the computer when the sensors on the arduino detect something, and that allows the computer to identify and play whichever sound file needs to be played, and the computer is capable of streaming wirelessly with ease too.

I already have the program that plays the files on the arduino written, for example, if pin2 goes high play sound file 5, then if day is monday play sound file 22 that says "monday" after file 5 is finished. But I want to transfer the logic of when to play which files that I wrote for the arduino to the computer so that the computer now does everything speaker wise and wifi server wise that the arduino use to do. I don't want to have to start from scratch though and re-write everything.

I don't understand this statement. The IDE can store the source code in a file, on any operating system. There are no Linux files directly attached to the Arduino. This whole statement doesn't make sense.

that's what I want to do. How do I do that so that the old code written for arduino (for example boolean switch=0;) will now work on the Linux program?

bool is the standard. Works on the Arduino, too. boolean is a non-standard extension that works only on the Arduino. Use the standard.

bool is shorter and quicker to write than boolean. why would any bozo use boolean on all the examples that come pre-loaded in the library that new programmers expect to be the right way to code, its more inefficient, than the universal and only works for arduino.

The standard in C++ is cout, but that writes to the console, the same as printf() does. The Arduino doesn't have a console, so cout and printf() are out.

Serial.print() and/or Serial.println() do what people normally use cout/printf() for.

just to be clear, are you saying Serial.print does what printf does, and Serial.println does what cout does in terms of print with/without line break automatically added?

While 1, HIGH, and true are all the same value, the context in which each is used is different. Effective communication means paying attention to context. YMMV.

I feel like there should be a tutorial that demonstrates when to use the different ways for universal communication somewhere on the arduino example library, or on the arduino site.

The sketch IS standard C++. That there are a lot of classes that are specific to the Arduino, and a completely different use of memory, which is in very limited supply on the Arduino, is what makes taking a program written for the Arduino just about unusable anywhere else.

Son of a *****! This is depressing...

The paradigm IS portable, and not that difficult to implement on a PC with tons of memory, a console, a file system, and an operating system. The converse (taking a PC program and fitting it onto the Arduino) is not necessarily easy or possible.

so are you saying that I can transfer the program logic written for arduino to a computer with not to much difficulty to implement just not vise versa? For example, when I tried to printf an int... the computer didn't like that at all, but when written for arduino its really easy to print an int...