How to connect Octoprint by serial port i2c with Raspi 3 B (Raspbian)?

I'm not having success with connection i2c!

I read and followed some tips of "Can't connect to printer" and of "Communication Problems using RPi 3", but It didn't work.

A message appear in terminal when I put additional serial port /dev/ttyS0:

Changing monitoring state from "Offline" to "Detecting serial port"
Serial port list: ['/dev/ttyS0']
Connecting to: /dev/ttyS0
Changing monitoring state from "Detecting serial port" to "Error: Connection error, see Terminal tab"
Unexpected error while connecting to serial port: AUTO SerialException: 'Could not configure port: (5, 'Input/output error')' @ comm.py:_openSerial:2469 (hook default)

Information about my setup
OctoPrint Version 1.3.9
Raspbian GNU/Linux 9.6 (stretch)
Marlin Version 1.1.9

  • Did you enable I2C in sudo raspi-config?
  • Probably a good idea to install some tools: sudo apt-get install -y i2c-tools
  • i2cdetect -y (look for something that isn't empty in the table)
  • Try to find the device: ls /dev/*i2c* (then look under this folder as well to be sure)
  • If a /dev/i2c-1 or similar folder exists then you've managed to enable the interface/device. It may be necessary to manually add the device into your ~/.octoprint/config.yaml file.

I'm not sure but I don't think I2C uses either of the two UARTs in the Raspi. I'm not sure what the maximum baudrate would be in a scenario like this. The size of the pull-up resistors are important to this but it may be necessary to adjust your firmware's speed down a notch.

Why are you using I2C? I haven't seen any 3D printer control board that uses anything besides USB or WiFi.

2 Likes

Yes, @OutsourcedGuru! Thank you for your considerations!
I have address 0x08 set in i2cdetect in the command that you list:

sudo i2cdetect -y 1

I'm using the i2C protocol because this protocol has less issues about conflict of communications between devices.
In my knowledge, Wifi has a high probability to have interference (EMI). USB has some issues, i.e., when I'm using arduino Mega and PC sometimes I have error of "timeout communicating with programmer...." of USB connection. These are the disadvantages of using these two forms.

Don't fret the timeout issues trying to flash a Mega board, it could be anything. But once you figure out the right combination to make the Arduino IDE or avrdude happy, you won't see that again. It's a question of properly identifying the board and the programming interface.

I have at least one Mega-based Arduino board and the IDE is happy which each of them. It seems to be the most straight-forward and painless way of flashing and it can deal with the boot loader part of all this if that's the problem. But avrdude is the only way I know of backing up the flash first so I use this as well. Here is a link to a discussion on the forum where I have shared the command I use to backup my board's flash. I don't have a programmer; I just use a serial cable and this translates to the avrispmkII within that command line.


I don't know of anyone trying to connect their Raspberry Pi to their Arduino board via wifi, for what it's worth. I suppose it could work, in theory.

OctoPrint under the hood utilizes pyserial to connect to the serial port of a printer. I'd be very surprised if that supports i2c communication. You might be able to get things to work with a custom wrapper plugin, but seriously, this just feels wrong.

Wifi has a high probability to have interference (EMI)

Which isn't an issue if you use TCP which has built-in error correction.

USB has some issues, i.e., when I'm using arduino Mega and PC sometimes I have error of "timeout communicating with programmer...." of USB connection.

That sounds more like an issue with your specific serial chipset or cabling. Serial via USB is very solid if implemented correctly (which admittedly it often times isn't on cheap printer boards). I rarely get any kind of throughput or communication issues with any of my FTDI based printers.