Hi, I have read some posts and blogs ( https://rr-m.org/blog/wp-content/uploads/2018/12/arduino_nano_thrustmaster_t300_ps_wheel_emulation_1600x1800.jpg)
And Im trying to replicate the same process, but instead of using the PS-Wheel that has 3 registers, Im trying to first, read and then, emulate SF1000 rim.
Im new using SPI, so, inspite of testing some codes (even from here Nano in SPI slave mode not able to write SPDR during SPI ISR routine) Im not able to get a good reading.
Setup is:
SF1000 conected as usual to T300 servo.
Arduino nano conected to t300 servo too (
D12 MISO
D13 SCK
D11 MOSI
D10 SS
GND
And my current coding attempt goes as:
#include<SPI.h>
byte myData[16] = {0x00};
void setup()
{
Serial.begin(9600);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV16);//1 MBits/s
digitalWrite(SS, LOW); //Slave is selected
//--------------------
}
void loop()
{
for (int i = 0; i < 16; i++)
{
myData[i] = SPI.transfer(myData[i]);
delayMicroseconds(100); //allows Slave to process received byte
Serial.print(myData[i], BIN);
Serial.print(" ");
}
Serial.println(" ");
delay(3000);
}
That, gives me a this:
11011101 11011101 11111111 11111111 11111111 11111110 1001010 0 0 0 0 10011100 1001010 11100010 1110000 10000101
1000000 0 0 11111111 11100000 0 10000000 0 0 10000000 0 0 0 0 0 0
And then, after those lines, all zeros, until close the serial monitor and reopen again.
Other attemp was using a code something like the rr-m blog, which consists in interfacing the rim with the arduino (the arduino is now the servo) with this code:
/* This sketch provided "AS IS" under the BSD New license.
http://opensource.org/licenses/BSD-3-Clause
April 2015 © blog@rr-m.org
download tx_rw_wheel_reader.ino above - it has more comments */
#include <SPI.h>
#include <Arduino.h>
const int slaveSelectPin = 7;
void setup() {
Serial.begin(9600);
SPCR |= _BV(CPHA);
SPCR |= _BV(CPOL);
SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE1));
SPI.begin();
pinMode(slaveSelectPin, OUTPUT);
}
void loop() {
// tell the wheel, that we gonna read the data now
digitalWrite(slaveSelectPin, LOW);
// read 3 bytes and output them to Arduino Serial monitor
// as binaries 11000001 11111111 11111111
// last 17 bits are buttons. 1 - released, 0 - pressed.
for(int i=1; i<=8; i++) {
delayMicroseconds(100);
printBinary(SPI.transfer(0x00));
}
Serial.println();
// release the wheel
digitalWrite(slaveSelectPin, HIGH);
// wait 1 second, then read data from wheel again
delay(1000);
}
// print byte as binary, zero padded if needed
// "127" -> "01111111"
void printBinary(byte data) {
for(int i=7; i>0; i--) {
if (data >> i == 0) {
Serial.print("0");
} else {
break;
}
}
Serial.print(data,BIN);
Serial.print(" ");
}
But, that gives a nonsense.
What im 100% positive, is that the first 5 bytes are:
11011101 11111111 11111111 11111111 11111110
but after that, nothing is logic. I have tried to put that bytes in arduino (from the same page) and the SF1000 is detected, but any push button is detected.
So, my questions are:
Which is better? trying to interface the sf1000 with arduino directly or keep connecting arduino as SPI slave to the t300 servo and read the sf1000 info?
Im at a dead end, as said, I dont have many knowledge about SPI, so, any help, or explanation on how to set
SPI.beginTransaction(SPISettings(MaxSpeed, MSBFIRST, SPI_MODEX));
Will be very appreciated.
Thanks in advance