supriono wrote:i want to cek data SPI from device like this (esp is slave)
how to print uint8_t * data (biner) to scopeCode: Select allSPISlave.onData([](uint8_t * data, size_t len) {
Serial.println(data,BIN);
}
);
i have this error
exit status 1
call of overloaded 'println(uint8_t*&, int)' is ambiguous
Hi,
Sorry, I'm not sure I understand the question.
First, you say you want to print the bytes "to scope". Serial.println() will send characters to the serial port, not to a "scope". If you pass an integer (e.g. 78) as first parameter and "BIN" as the second parameter, it will convert the integer to binary (1001110), then create a string with those 7 characters (seven times either '0' or '1') and send them to the serial port, so that the client on the other side will receive that string to, for example, display it in the terminal. If that's what you want, the 2-parameter Serial.println() is the right call.
Second, "data" is a "uint8_t *", that is a pointer to an unsigned int (or array of unsigned int), and there is no implementation of "Serial.println()" that expects a pointer to an unsigned int as first parameter and the constant (BIN) as second parameter. That's why you receive an error. What you probably want to do is dereference the pointer first, either using the "*" operator or, if it is part of an array, by indicating the element number between brackets.
Here is a full sketch illustrating the above :
void setup() {
Serial.begin(115200);
uint8_t a[] = {78,79,80};
printBin(a);
}
void loop() {}
void printBin(uint8_t* a) {
/* This does not compile because the compiler does not know how to print a pointer to uint8_t as you have noticed */
// Serial.println(a, BIN);
// Serial.println();
/* This works and prints (in binary) the value of the uint8_t pointed to by a */
Serial.println(*a, BIN);
Serial.println("--------");
/* This works and prints (in binary) the value of the first element of a, considered as an array (same result) */
Serial.println(a[0], BIN);
Serial.println("--------");
/* This works and prints(in binary) the value of the 2nd and 3rd elements of a, considered as an array */
Serial.println(a[1], BIN);
Serial.println(a[2], BIN);
Serial.println("--------");
/* This works and prints the value of all elements of a, considered as an array (same result as the 3 calls before) */
for (int i = 0; i < 3; i++) {
Serial.println(a[i], BIN);
}
Serial.println("--------");
}
The output on the serial monitor is :
1001110
--------
1001110
--------
1001111
1010000
--------
1001110
1001111
1010000
--------
In other words, change
Serial.println(data,BIN);
to
Serial.println(*data,BIN);
and you will print the value of the first byte in "data".
Hope it helps
Vicne