RESOLVED - Stream.write() - File.write() :: Write Number of Bytes

Edit: The compilation errors occur because the first parameter needs to be uint8_t.


https://www.arduino.cc/en/serial/write
https://www.arduino.cc/en/Reference/FileWrite

I am having some trouble decrypting my compilation errors. The documentation isn't quite clear on the parameters, but I can't even tell which parameter the errors are talking about; the first or the second.

Note: I am using an ESP32, so the libraries might not be the same, but I thought they should be the same.

#include "FS.h"
#include "SD.h"
#include "SPI.h"

char buff[20] = "1234567890123456789";
int c = 19;

void setup() {
  Serial.begin(115200);
  
  File file = SD.open("test.txt", FILE_APPEND);
  file.write(buff, c);
  Serial.write(buff, c);
}

void loop() {
  // put your main code here, to run repeatedly:

}
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "ESP32 Pico Kit, 921600, None"

C:\...\AppData\Local\Temp\arduino_modified_sketch_219423\sketch_apr30a.ino: In function 'void setup()':

sketch_apr30a:12:21: error: invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

   file.write(buff, c);

                     ^

In file included from C:\Users\Sean\AppData\Local\Temp\arduino_modified_sketch_219423\sketch_apr30a.ino:1:0:

C:\...\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.2\libraries\FS\src/FS.h:55:12: note:   initializing argument 1 of 'virtual size_t fs::File::write(const uint8_t*, size_t)'

     size_t write(const uint8_t *buf, size_t size) override;

            ^

sketch_apr30a:13:23: error: invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

   Serial.write(buff, c);

                       ^

In file included from C:\...\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.2\cores\esp32/Arduino.h:160:0,

                 from sketch\sketch_apr30a.ino.cpp:1:

C:\...\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.2\cores\esp32/HardwareSerial.h:67:12: note:   initializing argument 1 of 'virtual size_t HardwareSerial::write(const uint8_t*, size_t)'

     size_t write(const uint8_t *buffer, size_t size);

            ^

Multiple libraries were found for "SD.h"
 Used: C:\...\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.2\libraries\SD
 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\SD
exit status 1
invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

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

You error message says line 21 within setup() but the sketch you posted does not have 21 lines nor a line 21 within setup()

you can use write without second parameter or print for strings. the end is determined by terminating zero

blh64:
You error message says line 21 within setup() but the sketch you posted does not have 21 lines nor a line 21 within setup()

In the error message:

Thee_Captain:
sketch_apr30a:12:21: error: invalid conversion from 'char*' to 'const uint8_t* {aka const unsigned char*}' [-fpermissive]

file.write(buff, c);

^

The 21 part of 12:21 refers to the column number where the error occurred. The 12 part is the line number. That mixes me up pretty frequently.

pert:
In the error message:The 21 part of 12:21 refers to the column number where the error occurred. The 12 part is the line number. That mixes me up pretty frequently.

D'uh - me too :slight_smile: