Working on a solution for precision digital balances that provides input/output via RS232 and mini-USB. I have a Photon 2
I've got communication with the balance's RS232 working using Serial1, but I haven't had any luck getting any communication from the Photon 2's micro-USB to the balance's mini-USB port.
When I connect the scale to my PC via USB to miniUSB, I can send and receive data just fine using serial simulator software (which labels the device as "usbserial-DN02EQIX").
I've got code like Serial.write("P\r\n") that show up in the CLI Particle Serial Monitor, just have no response from the balance.
We've tried just about every cable combination...
Any ideas?
I'm pretty sure the Particle devices cannot be a USB host, which is what the balance is expecting to talk to. USB Serial is not like RS-232 and requires a host and peripheral role to communicate.
The good news is that there are some easy solutions by adding a bit more hardware. Adafruit sells this device that acts as a USB host and could talk to the balance (assuming it doesn't need a special software driver).
No Particle devices can behave as USB host without additional hardware, technically it would be USB OTG (on-the-go) because of the use of the Micro USB B connector on most Particle devices.
In addition to the RTL872x not supporting USB host, there's no hardware to power the port in OTG mode.
Do you believe the solution from @bko wouldn't work? It seems to connect to the board via SPI.
But if I'm understanding you correctly, the MCU itself doesn't support it so we may need to start looking at other hardware solutions.
EDIT: Following rickkas7's edit, I have ordered the part and will update on the result.
@bko@rickkas7 The Adafruit has since arrived, and it 's been set up with my Photon 2. Picture below. It's a little convoluted (one breadboard on hand) but a multimeter ensured it all connects where I want.
From Photon 2 >> MAX3421:
3v3 >> 3v0
GND >> GND
MI >> MI
MO >> MO
SCK >> SCK
S3/D18 >> CS
S4/D19 >> IRQ
Here is my code below, ran while a usb runs from the featherwing to the balance. Upon sending the last of three bytes (0x5A, 0x0D, 0x0A), I would expect three bytes to be returned just the same as serial.
#define ss D18
void setup()
{
SPI.begin(SPI_MODE_MASTER, ss);
SPI.setClockSpeed(1, MHZ);
Serial.begin(9600);
}
void loop()
{
SPI.transfer(0x5A); // 'Z'
SPI.transfer(0x0D); // '\r'
Serial.print(SPI.transfer(0x0A)); // '\n'
Serial.print(SPI.transfer(0)); // followed by two empty bytes to receive entire response.
Serial.print(SPI.transfer(0));
delay(5000);
}
I am only receiving "000" in the serial monitor, whether the balance is connected or not (I would expect either "OK!" or "ES"). I've looked a lot into any documentation with this featherwing and I've only found the library spark-usb-host which appears to be discontinued. I have not messed with the interrupt pin yet.
What am I missing?
The Adafruit board has a 3V3 to 5V converter but you can enable/disable it via a pin. I don't recall the default (on or off). And I don't know if your balance requires +5 on the USB port but I would think it expected it.
First thing to check:
Can you make sure the +5V USB converter is on? Is the green +5V LED turned on for the Adafruit board?
5V Enable Jumper - On the back of the FeatherWing is an open jumper. If you
solder this jumper closed you will connect the 5V enable pin to GPOUT0
(general purpose output 0) on the MAX3421E. This output is controllable over
SPI, which means you can then enable or disable 5V to the USB-A port in
software.
I'm not sure if this means it must also be done in software, in which case it must be looked into further. I've now soldered the 5V jumper, and multimeter confirmed the gap was bridged. However I don't get the LED. The highest reading from poking around the featherwing is 3.3v, instead of 5v. Same result "000".
I will be drawing up a wiring diagram, and will likely share here for ease of reading.
I was curious about that TX and RX pin...
I have nothing currently wired to it and I couldn't find any mention of them in the MAX3421 or featherwing docs.
Featherwing TX and RX bridge response: "000"
Feather TX and RX to Photon 2 RX and TX: "000"
Feather TX and RX to Photon 2 TX and RX: "000"
Looking at spark-usb-host this is a download of the USB Host Shield 2.0 library. I have tried that and it worked with an UNO R3. The instructions are to download the zip file and manually work it into the library structure of files. Have not tried building it yet.
There is an Adafruit TinyUSB library which on the surface is more appealing but appears to not support the RealTek CPU. Anyone had any experience with this?