pavel-demin / red-pitaya-notes

Notes on the Red Pitaya Open Source Instrument
http://pavel-demin.github.io/red-pitaya-notes/
MIT License
337 stars 209 forks source link

Accessing GPIOs from software in pulsed_nmr #1089

Closed pasicl closed 1 year ago

pasicl commented 1 year ago

Description of the setup:

Device: 125-14-Z7020-LN SD card image: red-pitaya-alpine-3.14-armv7-20220322 Application: pulsed_nmr Description of the problem:

Description of the problem:

I am trying to acess the GPIO of the Red Pitaya in the pulsed_nmr application. However, I don't know how can I do that. I have seen that the FPGA contains the outputs exp_p_io and exp_n_io, but I don't know where to start to adress them. I need to write either HIGH or LOW from the C server or the Python Client.

pavel-demin commented 1 year ago

Commands to set and clear pins are defined in the C# client: https://github.com/pavel-demin/red-pitaya-notes/blob/develop/projects/pulsed_nmr/client/PulsedNMR.cs#L93-L101

They can be easily ported to Python:

  def set_pin(self, pin):
    if self.idle: return
    self.socket.write(struct.pack('<Q', 4<<60 | int(pin)))

  def clear_pin(self, pin):
    if self.idle: return
    self.socket.write(struct.pack('<Q', 5<<60 | int(pin)))

The controlled pins are DIO1_P - DIO7_P.