@RWB The opto is spec’ed at 10mA and the diode drops about 1.4V (middle of specs), so you could use 190 Ohms on the diode. A more practical value for a digital application is around 5mA, so 330 Ohms will work fine. I would lean towards a lower resistor value to account for aging and CTR variation effects.
The output resistor depends on the speed you are trying to achieve. The BJT can drive 50mA, so at 3.3V the output pull-up can be as low as 60 Ohms. These are the max values, but more appropriate would be 500 Ohms. 470 is fine.
You should check how fast the output needs to toggle. This is not a particularly fast opto with prop delay of 100usec.
There are so many better options and in 4 pin packages and with higher CTR at lower diode currents. All depends on cost, size and availability criteria.
BTW, if you can drive the diode from the cathode instead of the anode, the output will not be inverted.
The 330 ohm as used in the example? Based on the scope pictures it looks like they were working with 5v input and 4v on the output. I’m 5v in and the output is running to the Photon is 5v tolorent on the D2 pin I’m using for Softserial at 19,200baud.
The device is a solar charge controller and its UART data on RX was 4.5v on the scope. This was on Softserial but the exact same happened when connected to Serial2.
When I attached a battery monitor to the Serial1 the Softserial stopped receiving data unless I temporarily disabled Serial1. The Softserial worked fine if I discnnected the battery monitor which is what lead me to try toggling Serial1 Off for a short period of time.
Turning Serial OFF does not fix a ground loop does it?
I looked at the signals with an oscilloscope from both sources at the same time while connected and they look nice and clean and I didn’t see any noticable changes when I connected or disconnected the devices.
If you are careful with the power connections for the optoisolators, then yes they will get you out of ground problems. So in your schematics above, exactly which +5 and which GND you are using is key. If the GND pins on the two sides of the optoisolator are not connected together, that will work OK but your schematic does not indicate that.
Turning off serial makes all the pins be high impedance inputs (with protection diodes) so that can possibly open a ground problem. A no-ground situation can cause inputs to float and work at some times and not others as well.
Your scope also has a hard ground which is typically connected from the probe to earth safety ground. This is normally a good thing for your safety but there are times when you must run a scope without a safety ground on a isolation transformer. I have seen cases where the scope probe ground wire acted like a fuse and melted due to high current.
I am not saying that your problem was absolutely a ground problem; I’m just saying that your strange symptoms do fit that hypothesis. If you don’t know for sure how the systems are grounded, you could poke around a bit with your scope and likely find out. Try connecting the scope probe tip and only the tip to one system’s GND pin and see if there is DC there. Look at the other pins relative to earth ground too. Then try the other system.