Git Product home page Git Product logo

jetgpio's People

Contributors

littlebluesub avatar pintarj avatar rubberazer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jetgpio's Issues

cant run on boot

hi,
i used your library , its wonderful and work but i have some diffucult for example
i run it in terminal with sudo ./myApp its worked but when i did with myapp.service its not running. path is correct. permission is chmod +x myApp and i try chmod 777 myApp. can you try work on boot or do you have any idea.
i tried that, with desktop file, with service file, with .sh file . it not worked. but other app did works fine

thanks for your help
regards

i have solition just now, may be need someone.
make StartUp Application comman in ubuntu menu .sh file and your app in same folder
like this. /path/your/myAppsh.sh
myAppsh.sh:
#!/bin/bash
echo <your_pass> | sudo -S ./myApp

thats all.
thank you for library

gpioRead read does not work with output pins

gpioRead( ) does not work when the pin is in output mode.

This may be by design, but it would be nice option if it could. For what it is worth, the wiringPi library returns the state of the pin when you call digital read for both input and output mode pins.

The code could look something like this:


int gpioRead(unsigned gpio)
{
	int level = 0;
	switch (gpio) 
	{
	case 3:
		if (*pinmux3 == PINMUX_IN)
			level = (pin3->IN[0]) >> 3 & 1;
		else
			level = (pin3->OUT[0]) >> 3 & 1;
		break;
	case 5:
		if (*pinmux5 == PINMUX_IN)
			level = (pin5->IN[0]) >> 2 & 1;
		else
			level = (pin5->OUT[0]) >> 2 & 1;
		break;
	case 7:
		if (*pinmux7 == PINMUX_IN)
			level = pin7->IN[0] & 1;
		else
			level = pin7->OUT[0] & 1;
		break;
	case 8:
		if (*pinmux8 == PINMUX_IN)
			level = pin8->IN[0] & 1;
		else
			level = pin8->OUT[0] & 1;
		break;
	case 10:
		if (*pinmux10 == PINMUX_IN)
			level = (pin10->IN[0]) >> 1 & 1;
		else
			level = (pin10->OUT[0]) >> 1 & 1;
		break;

Makefile was missing call to: -lpthread -lrt

Corrected stupid mistake on the github makefile, everything should be working fine now. Unfortunately versions downloaded from the 22nd October to the 5th of November need to add this correction, if not the library is going to fail
ANOBODY WHO DOWNLOADED BETWEEN THE 22ND OCTOBER AND THE 5TH OF NOVEMBER SHOULD CLONE/DOWNLOAD AGAIN

Reading issue on Jetson Orin Nano

Hi Rubberazer,

First of all, thanks a lot for providing a library to use Jetson GPIOs in C, very helpful.

I have an issue reading an input on my Jetson Orin Nano. I don't think the issue is related to the library itself, but rather a configuration pin issue. However, I hope you might maybe give some advice.

When I press a button, I send a PWM (servo) signal to pin 15 of my Jetson Orin Nano. I am aware that the library has no function to read PWM, but I was able to write a custom code that worked with another system. I registered an ISR function that is supposed to be called and read the PWM. Currently, the ISR is never called. I made another test code using gpioRead() to print the pin level in the terminal and there is no change when I press the button. Finally, looking with an oscilloscope, I can see the PWM signal, but it is only 300mV at high state. When my remote controller is not connected to the Jetson, the PWM signal level is fine.

I assume I need to configure the pin, because it seems to currently pull-down the line. Have you encountered a similar issue before?

Thank you,

Leane

how to improve the speed of spi communication?

I ran the "spi_loop.c " to get data from ad7606, the frequency is 3khz. But i need more than 20khz, Is there other method to improve the spi communication speed?

here is my modified code of SPI_loop.c:
//gcc -Wall -o spi_loop spi_loop.c -ljetgpio
//sudo ./spi_loop
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <jetgpio.h>
#include <time.h>

struct timespec start, end;
double elapsed_time;
void ADC7606_Reset()
{
gpioWrite(16, 1);
gpioWrite(16, 0);
}

void Convert_Volt(uint16_t* input, float* output, int inputSize) {
const float lsb_voltage = 5.0f / 32768.0f;

for (int i = 0; i < inputSize; i++) {
    int16_t signedInput = (int16_t)input[i];
    if (input[i] > 32767) {
        signedInput = (int16_t)(input[i] - 65536);
    }
    output[i] = signedInput * lsb_voltage;
}

}

int main(int argc, char *argv[])
{
int Init;
int SPI_init;
int SPI_stat;
uint16_t tx[4] = {0,};
uint16_t rx[4] = {0,};
float voltages[4] = {0};

Init = gpioInitialise();
if (Init < 0)
{
    printf("Jetgpio initialisation failed. Error code: %d\n", Init);
    return EXIT_FAILURE;
}
else
{
    printf("Jetgpio initialisation OK. Return code: %d\n", Init);
}

gpioSetMode(15, JET_OUTPUT); 
gpioSetMode(16, JET_OUTPUT);  
gpioSetMode(18, JET_INPUT); 

SPI_init = spiOpen(0, 50000000, 0, 0, 16, 0, 1); 
if (SPI_init < 0)
{
    printf("Port SPI1 opening failed. Error code: %d\n", SPI_init);
    return EXIT_FAILURE;
}
else
{
    printf("Port SPI1 opened OK. Return code: %d\n", SPI_init);
}

ADC7606_Reset();

while (1)
{
    clock_gettime(CLOCK_MONOTONIC, &start);
    gpioWrite(15, 1);
    gpioWrite(15, 0);
    while(gpioRead(18) == 0)
    {}
    gpioWrite(24, 0);
    SPI_stat = spiXfer(SPI_init, (char*)tx, (char*)rx, 8 * sizeof(uint16_t));
    if (SPI_stat < 0)
    {
        printf("SPI port transfer failed. Error code: %d\n", SPI_stat);
        break;  
    }
    gpioWrite(24, 1);
    clock_gettime(CLOCK_MONOTONIC, &end);

    elapsed_time = (end.tv_sec - start.tv_sec) * 1e9;
    elapsed_time = (elapsed_time + (end.tv_nsec - start.tv_nsec)) * 1e-9;

    printf("Elapsed time: %f seconds\n", elapsed_time);

    printf("Data received:\n");
    for (int j = 0; j < 4; j++) { 
        printf("tx%d:%x --> rx%d:%x\n", j+1, tx[j], j+1, rx[j]);
    }

    Convert_Volt(rx, voltages, 4); 

    for (int i = 0; i < 4; i++) {
        printf("Channel %d: %f V\n", i+1, voltages[i]);
    }

    memset(rx, 0, sizeof(rx));
}   

spiClose(SPI_init);
gpioTerminate();
return EXIT_SUCCESS;

}

Qt and jetgpio_example.cpp problem

hi, first of all thank you for pair for code..
my problem that, i am using Qt and i make copy code in jetgpio_example.cpp to mainwindow.cpp but editor show error
undefined reference to gpioInitialise' undefined reference to gpioSetMode'
and other function, i did add in header #include <jetgpio.h> and read installation doc. make and make install, by the way , if i run jetgpio_example.cpp in with this way
Compile with: g++ -Wall -o jetgpio_example jetgpio_example.cpp -ljetgpio

  • Execute with: sudo ./jetgpio_example
    everything is okey. but in Qt doesnt work.
    have you got any idea..or solition

#include <stdint.h>
#include <stdlib.h>
#include <jetgpio.h>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
int Init;

Init = gpioInitialise();
if (Init < 0)
{
   /* jetgpio initialisation failed */
   printf("Jetgpio initialisation failed. Error code:  %d\n", Init);
   exit(Init);
}
else
{
   /* jetgpio initialised okay*/
   printf("Jetgpio initialisation OK. Return code:  %d\n", Init);
}

// Setting up pin 3 as OUTPUT and 7 as INPUT

int stat1 = gpioSetMode(3, JET_OUTPUT);
if (stat1 < 0)
{
   /* gpio setting up failed */
   printf("gpio setting up failed. Error code:  %d\n", stat1);
   exit(Init);
}
else
{
   /* gpio setting up okay*/
   printf("gpio setting up okay. Return code:  %d\n", stat1);
}

int stat2 = gpioSetMode(7, JET_INPUT);
if (stat2 < 0)
{
   /* gpio setting up failed */
   printf("gpio setting up failed. Error code:  %d\n", stat2);
   exit(Init);
}
else
{
   /* gpio setting up okay*/
   printf("gpio setting up okay. Return code:  %d\n", stat2);

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{

ui->setupUi(this);
int Init;

Init = gpioInitialise();
if (Init < 0)
{
   /* jetgpio initialisation failed */
   printf("Jetgpio initialisation failed. Error code:  %d\n", Init);
   exit(Init);
}
else
{
   /* jetgpio initialised okay*/
   printf("Jetgpio initialisation OK. Return code:  %d\n", Init);
}

// Setting up pin 3 as OUTPUT and 7 as INPUT

int stat1 = gpioSetMode(3, JET_OUTPUT);
if (stat1 < 0)
{
   /* gpio setting up failed */
   printf("gpio setting up failed. Error code:  %d\n", stat1);
   exit(Init);
}
else
{
   /* gpio setting up okay*/
   printf("gpio setting up okay. Return code:  %d\n", stat1);
}

int stat2 = gpioSetMode(7, JET_INPUT);
if (stat2 < 0)
{
   /* gpio setting up failed */
   printf("gpio setting up failed. Error code:  %d\n", stat2);
   exit(Init);
}
else
{
   /* gpio setting up okay*/
   printf("gpio setting up okay. Return code:  %d\n", stat2);
}

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
int Init;

Init = gpioInitialise(); //**_<---- problem this line,**_
if (Init < 0)
{
   /* jetgpio initialisation failed */
   printf("Jetgpio initialisation failed. Error code:  %d\n", Init);
   exit(Init);
}
else
{
   /* jetgpio initialised okay*/
   printf("Jetgpio initialisation OK. Return code:  %d\n", Init);
}

// Setting up pin 3 as OUTPUT and 7 as INPUT

int stat1 = gpioSetMode(3, JET_OUTPUT);
if (stat1 < 0)
{
   /* gpio setting up failed */
   printf("gpio setting up failed. Error code:  %d\n", stat1);
   exit(Init);
}
else
{
   /* gpio setting up okay*/
   printf("gpio setting up okay. Return code:  %d\n", stat1);
}

int stat2 = gpioSetMode(7, JET_INPUT);
if (stat2 < 0)
{
   /* gpio setting up failed */
   printf("gpio setting up failed. Error code:  %d\n", stat2);
   exit(Init);
}
else
{
   /* gpio setting up okay*/
   printf("gpio setting up okay. Return code:  %d\n", stat2);
}

///-------------------------------------------------------------------///

thank you...
assyhgit

I2C does not allow for multiple devices on the same bus

As a user, I need to have multiple I2C devices on the same bus.

In the function jetgpio.c / i2cOpen( )

This code (around line 1969) prevents more than one device on the same bus:

if (i2cInfo[i2cBus].state == I2C_CLOSED) {
slot = i2cBus;
i2cInfo[slot].state = I2C_RESERVED;
}
else { printf("i2c bus already open\n");
return -4;
}

Orin NX PWM minimum freq?

I'm running this on an Orin NX and I'm confused as to why the minimum PWM frequency is 400 Hz. As far as I'm aware, this locks me out of most servo and motor control (since those are usually 50-100Hz). Would it be possible to go around whatever limitation this is to enable said servo and motor control? Thanks!

Thank you for this library

This is not an issue, but a thank you.

I am new to working with Jetson, starting with some experience with the Raspberry Pi using wiringPi.

Thank you very much for creating and sharing this library. It was the only C library I could find that worked on both the NVIDIA developer carrier board and the Seeed Studio A203 carrier board I am using for my projects.

Thank you again

Graham Briggs

About PWM

Hi,
I have a Jetson Nano Developer Kit and I want to drive an SG90 servo motor (TowerPro Mİcro Serve 9g) using PWM. I can partially drive it. I downloaded and installed your library. However, I encountered an interesting issue. When I set the frequency to 50 Hz with the 'gpioSetPWMfrequency' function, I observe 45 Hz on the oscilloscope, and when I set it to 55 Hz, I see 50 Hz. What could be the reason for this? Have you encountered or seen any similar issues before? I am connecting the pins directly without using a resistor in between. I would greatly appreciate your help. Thank you in advance.

latency measurement

I didnt find, but maybe its already on docs, can you share the latency of JetGPIO lib comparing gpiod?

I2C communication bus speed path not found.

I am having issue using the i2c communication on the Jetson Nano Orin. My jetpack version is 6.0-b52 and the os version is ubuntu 22.04.4 LTS.

I am getting this error when I try to open the I2C bus : Not possible to read current bus speed. Segmentation fault.

By looking into the orin.c it seems that the file path for the bus speed file is no longer the same for with version I use. I will keep looking for the rigth path.

Thanks in advance for your help.

segfault on GPIO configure

Jetson Orin Nano

# R35 (release), REVISION: 3.1, GCID: 32827747, BOARD: t186ref, EABI: aarch64, DATE: Sun Mar 19 15:19:21 UTC 2023

The below error is caused when setting the GPIO to an OUTPUT.

[ 1742.458497] ---[ end trace c9b4cbc2ab4c73c3 ]---
[ 1796.382888] CPU:0, Error: cbb-fabric@0x13a00000, irq=25
[ 1796.388290] **************************************
[ 1796.393217] CPU:0, Error:cbb-fabric, Errmon:2
[ 1796.397703] 	  Error Code		: FIREWALL_ERR

[ 1796.403372] 	  Error Code		: FIREWALL_ERR
[ 1796.407497] 	  MASTER_ID		: CCPLEX
[ 1796.410993] 	  Address		: 0x32e0000
[ 1796.414580] 	  Cache			: 0x0 -- Device Non-Bufferable
[ 1796.419771] 	  Protection		: 0x2 -- Unprivileged, Non-Secure, Data Access
[ 1796.426747] 	  Access_Type		: Read
[ 1796.430238] 	  Access_ID		: 0x15
[ 1796.430242] 	  Fabric		: cbb-fabric
[ 1796.437136] 	  Slave_Id		: 0x35
[ 1796.440356] 	  Burst_length		: 0x0
[ 1796.443845] 	  Burst_type		: 0x1
[ 1796.447157] 	  Beat_size		: 0x2
[ 1796.450373] 	  VQC			: 0x0
[ 1796.453149] 	  GRPSEC		: 0x7e
[ 1796.456195] 	  FALCONSEC		: 0x0
[ 1796.459425] 	**************************************
[ 1796.464467] ------------[ cut here ]------------
[ 1796.464486] WARNING: CPU: 0 PID: 0 at drivers/soc/tegra/cbb/tegra234-cbb.c:577 tegra234_cbb_isr+0x130/0x170
[ 1796.474494] Modules linked in: nvidia_modeset(OE) fuse(E) lzo_rle(E) lzo_compress(E) zram(E) ramoops(E) reed_solomon(E) loop(E) bnep(E) snd_soc_tegra186_asrc(E) snd_soc_tegra186_dspk(E) snd_soc_tegra210_ope(E) snd_soc_tegra210_mvc(E) snd_soc_tegra210_iqc(E) snd_soc_tegra186_arad(E) snd_soc_tegra210_afc(E) snd_soc_tegra210_dmic(E) snd_soc_tegra210_admaif(E) snd_soc_tegra210_adx(E) snd_soc_tegra210_amx(E) snd_soc_tegra_pcm(E) snd_soc_tegra210_mixer(E) snd_soc_tegra210_i2s(E) snd_soc_tegra210_sfc(E) aes_ce_blk(E) crypto_simd(E) cryptd(E) aes_ce_cipher(E) ghash_ce(E) rtl8822ce(E) r8168(E) sha2_ce(E) sha256_arm64(E) sha1_ce(E) rtk_btusb(E) btusb(E) snd_soc_tegra210_adsp(E) btrtl(E) btbcm(E) btintel(E) snd_soc_tegra_machine_driver(E) snd_soc_spdif_tx(E) snd_soc_tegra_utils(E) snd_hda_codec_hdmi(E) snd_soc_simple_card_utils(E) snd_soc_tegra210_ahub(E) r8169(E) realtek(E) userspace_alert(E) fusb301(E) tegra_bpmp_thermal(E) nvadsp(E) snd_hda_tegra(E) tegra210_adma(E) cfg80211(E) snd_hda_codec(E)
[ 1796.474603]  nv_imx219(E) snd_hda_core(E) spi_tegra114(E) nvidia(OE) binfmt_misc(E) ina3221(E) pwm_fan(E) nvgpu(E) nvmap(E) ip_tables(E) x_tables(E) [last unloaded: mtd]
[ 1796.474630] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G        W  OE     5.10.104-tegra #1
[ 1796.474632] Hardware name: NVIDIA Orin NX Developer Kit (DT)
[ 1796.474636] pstate: 60400089 (nZCv daIf +PAN -UAO -TCO BTYPE=--)
[ 1796.474638] pc : tegra234_cbb_isr+0x130/0x170
[ 1796.474640] lr : tegra234_cbb_isr+0x10c/0x170
[ 1796.474642] sp : ffff800010003e10
[ 1796.474643] x29: ffff800010003e10 x28: ffffd05082682680 
[ 1796.474646] x27: 0000000000000001 x26: 0000000000000080 
[ 1796.474649] x25: ffffd050820a7778 x24: ffffd050829ebe40 
[ 1796.474652] x23: ffffd05082387000 x22: 0000000000000019 
[ 1796.474655] x21: ffffd0508280ef20 x20: 0000000000000002 
[ 1796.474657] x19: ffffd0508280ef10 x18: 0000000000000010 
[ 1796.474660] x17: 0000000000000000 x16: ffffd050809e2d90 
[ 1796.474662] x15: ffffd05082682bf0 x14: ffffffffffffffff 
[ 1796.474665] x13: ffff800090003917 x12: ffff80001000391f 
[ 1796.474667] x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f 
[ 1796.474670] x9 : ffff800010003c30 x8 : 2a2a2a2a2a2a2a2a 
[ 1796.474672] x7 : 2a2a2a2a2a2a2a09 x6 : c0000000ffffefff 
[ 1796.474675] x5 : ffff7787a8377958 x4 : ffffd05082697968 
[ 1796.474677] x3 : 0000000000000001 x2 : ffffd05080b77460 
[ 1796.474679] x1 : ffffd05082682680 x0 : 0000000100010001 
[ 1796.474683] Call trace:
[ 1796.474685]  tegra234_cbb_isr+0x130/0x170
[ 1796.474694]  __handle_irq_event_percpu+0x60/0x2a0
[ 1796.474697]  handle_irq_event_percpu+0x3c/0xa0
[ 1796.474699]  handle_irq_event+0x4c/0xf0
[ 1796.474701]  handle_fasteoi_irq+0xbc/0x170
[ 1796.474705]  generic_handle_irq+0x3c/0x60
[ 1796.474707]  __handle_domain_irq+0x6c/0xc0
[ 1796.474712]  gic_handle_irq+0x64/0x130
[ 1796.474713]  el1_irq+0xd0/0x180
[ 1796.474720]  cpuidle_enter_state+0xb4/0x400
[ 1796.474722]  cpuidle_enter+0x3c/0x50
[ 1796.474726]  call_cpuidle+0x40/0x70
[ 1796.474727]  do_idle+0x1fc/0x260
[ 1796.474729]  cpu_startup_entry+0x28/0x70
[ 1796.474737]  rest_init+0xd8/0xe4
[ 1796.474744]  arch_call_rest_init+0x14/0x1c
[ 1796.474746]  start_kernel+0x50c/0x540
[ 1796.474748] ---[ end trace c9b4cbc2ab4c73c4 ]---

gpioTerminate sets all pins back to their original state

gpioTerminate( ) will set all pins back to their original state.

I am sure this is by design. I suggest this is a bad design, because it means you can not reliably have more than one program using this library at the same time.

Consider this scenario

  1. Program A starts, initializes the state of all pins
  2. Program A is using pins 38 and 40, so sets those to desired mode
  3. Program B starts, initializes state of all pins
  4. Program B is using pins 29 and 30, so sets those pins to desired mode
  5. Program A exits, it will reset pins 29 and 30 to their original state, which might not be desired state of program B, which is still running. Chaos will ensue.

Suggest that gpioTerminate should only reset the state of pins that have been initialized through call to pinMode in this instance of the program. Alternatively, do not reset pin mode state at all and make this a deliberate choice of the app using the library what to do with pins when it shuts down.

spi max speed problem?

I tried your code with the orin agx,

but it seems that if I set the spi max speed to 500kHz, the communication works well but If I increase it higher than that, the communication becomes weird, is there some possible reason? I see that your original sample code sets the spi max speed to 5Mhz so it seems that higher spi speed is possible for you?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.