testing input and output on the BeagleY-AI

I have this source. I am testing it now and I have come to a stalemate so far with I/O.

I am receiving my Input only as Output on the console instead of my Input being a LED signifying the Input was an Event.

Here is the random source. Can you see where I am going incorrect here?

#!/usr/bin/python3

# Testing Motors Again
# Dictionary from https://www.cl.cam.ac.uk/ and ideas

import gpiod
from time import sleep

chip_path_one = "/dev/gpiochip3"
chip_path_two = "/dev/gpiochip2"

line_offset_one = 14
line_offset_two = 38

CODE = {' ': ' ',
        "'": '.----.',
        '(': '-.--.-',
        ')': '-.--.-',
        ',': '--..--',
        '-': '-....-',
        '.': '.-.-.-',
        '/': '-..-.',
        '0': '-----',
        '1': '.----',
        '2': '..---',
        '3': '...--',
        '4': '....-',
        '5': '.....',
        '6': '-....',
        '7': '--...',
        '8': '---..',
        '9': '----.',
        ':': '---...',
        ';': '-.-.-.',
        '?': '..--..',
        'A': '.-',
        'B': '-...',
        'C': '-.-.',
        'D': '-..',
        'E': '.',
        'F': '..-.',
        'G': '--.',
        'H': '....',
        'I': '..',
        'J': '.---',
        'K': '-.-',
        'L': '.-..',
        'M': '--',
        'N': '-.',
        'O': '---',
        'P': '.--.',
        'Q': '--.-',
        'R': '.-.',
        'S': '...',
        'T': '-',
        'U': '..-',
        'V': '...-',
        'W': '.--',
        'X': '-..-',
        'Y': '-.--',
        'Z': '--..',
        '_': '..--.-'}

def dot():
        gpio8.set_value(1)
        sleep(0.2)
        gpio8.set_value(0)
        sleep(0.2)

def dash():
        gpio8.set_value(1)
        sleep(0.6)
        gpio8.set_value(0)
        sleep(0.2)

def text_to_morse(text):
    morse_code = ''
    for char in text.upper():
        morse_code += CODE.get(char, '') + ' '
    return morse_code.strip()

def morse_to_text(morse):
    text = ''
    morse_words = morse.split('   ')  # Split by triple spaces for words
    for word in morse_words:
        morse_chars = word.split(' ')
        for char in morse_chars:
            for key, value in CODE.items():
                if value == char:
                    text += key
                    break
        text += ' '
    return text.strip()

gpio8 = gpiod.find_line("GPIO14")
gpio8.request(consumer="BeagleY-AI", type=gpiod.LINE_REQ_DIR_OUT, default_val=0)

gpio7 = gpiod.find_line("GPIO4")
gpio7.request(consumer="BeagleY-AI", type=gpiod.LINE_REQ_DIR_IN, default_val=0)

try:
    while True:
        inp = input('What shall we send...?\n')
        for letter in inp:
            for symbol in CODE[letter.upper()]:
                if symbol == '-':
                    dash()
                elif symbol == '.':
                    dot()
                else:
                    sleep(1)
        sleep(1)

        text = inp
        morse = text_to_morse(text)
        print(f"Text: {text}")
        print(f"Morse: {morse}")
        translated_text = morse_to_text(morse)
        print(f"Translated: {translated_text}")

        if gpio7.get_value() == True:
            for letter in text:
                for symbol in CODE[letter.upper()]:
                    print(f'Here: {text}')
                    sleep(1)
                    gpio8.set_value(1)
        else:
            gpio7.get_value() == False
            gpio8.set_value(0)

except KeyboardInterrupt:
    gpio8.set_value(0)
    pass
    print("Hey...done for now?\n")

So, if inp equals my input, say FF or gg or whatever, the remorse.py file has a LED in the physical world that lights up in Morse Code but then just lights up once the input event has happened. Also, the switch once tapped already lights the LED at the end of the source that runs until I CTRL-C the script or it repeats in asking for input.

The first section of the source works. Morse Code works but my I/O is a bit off…

Seth

One question again…

If "/dev/gpiochip3" works in Python but not in C/C++, what would be the issue?

For instance:

// Some C File

#include <gpiod.h>

...

  char *chipname = "/dev/gpiochip3";

...

The above source does not work for some reason in C/C++. When I call the *chipname and after compiling correctly, the error is my own error on the console. So, everything on the compiler side works but my error catch in my source is caught up even after the correct compilation.

import gpiod

...

chip = '/dev/gpiochip3'
line = 38

...

This is working for some reason. I do not know why yet. If you know, please jump on in…

Seth

Here is one a did for the orin nano board a while back. It outputs to the speaker not gpio. It might have a something you can use.

1 Like

Neat…I never thought about sound, i.e. I gave up sound. I am working with GPIO only for now.

I think I installed the incorrect gpiod. I will test soon. Thank you.

Seth

I think I got something working.

I can close this issue now. So, what I do not have working so far is the I to O.

So, Input (I) works and so does Output (O). I just cannot get Output to take in Input with GPIOD.

Seth

P.S. I will keep testing.