Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions GPIOSetup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# file: GPIOSetup.sh
# http://elinux.org/Jetson/GPIO
#

$ sudo su
$ cat /sys/kernel/debug/gpio

$ echo 57 > /sys/class/gpio/export
$ echo out > /sys/class/gpio/gpio57/direction
$ echo 1 > /sys/class/gpio/gpio57/value
$ cat /sys/kernel/debug/gpi

$ echo 57 > /sys/class/gpio/unexport
$ cat /sys/kernel/debug/gpi

$ exit

# AFTER cat /sys/kernel/debug/gpio RUNS
# GPIOs 0-255, platform/6000d000.gpio, tegra-gpio:
# gpio-58 (vdd-lcd-bl-en ) out lo
# gpio-59 (panel rst ) out lo
# gpio-63 (avdd-hdmi-pll ) out lo
# gpio-70 (temp_alert ) in hi
# gpio-82 (raydium-irq ) in lo
# gpio-84 (raydium-reset ) out lo
# gpio-86 (vdd-hdmi ) out hi
# gpio-108 (usb0-vbus ) in lo
# gpio-109 (usb1-usb2-vbus ) in hi
# gpio-111 (hdmi_hpd ) in hi
# gpio-122 (vdd-lcd-bl ) out lo
# gpio-128 (Power ) in hi
# gpio-132 (sdhci_wp ) in hi
# gpio-136 (sdmmc-en-supply ) out lo
# gpio-138 (reg-dcdc-1v2 ) out hi
# gpio-143 (headphone detect ) in hi
# gpio-170 (sdhci_cd ) in hi
# GPIOs 1016-1023, platform/as3722-pinctrl, as3722-gpio, can sleep:
# gpio-1018 (as3722-gpio2-supply ) out hi
# gpio-1020 (as3722-gpio4-supply ) out lo
#

# AFTER echo 57 > /sys/class/gpio/export RUNS
# gpio-57 (sysfs ) out hi #gpio-57 NOW SHOWS UP IN TABLE
Binary file added GPIOTestApplication
Binary file not shown.
105 changes: 105 additions & 0 deletions GPIOTestApplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* GPIOTestApplication.cpp
* An example main driver program to excerise JetsonGPIO.cpp
*
* Author: Blaze Sanders SpaceVR(TM) June 2016
* Link: http://elinux.org/Jetson/GPIO
*
* Note: The GPIO pins on Jetson TK1 are all 1.8V logic and can only
* supply a few milli-amps of current, so you can't simply attach common
* 5V or 3.3V logic signals or devices. One-way opto-isolated level shifter
* are the preffered method for connecting the TK1 to external devices,
* since its a more rugged method (www.sparkfun.com/products/9118).
*/

#include <iostream> //Standard input/output stream objects, needed to use cout()
#include <chrono> //High accuracy microsecond timing
#include <unistd.h> //Standard symbolic constants & types, needed to use usleep()

#include "JetsonGPIO.h"

using namespace std;

//Compiled using g++ GPIOTestApplication.cpp JetsonGPIO.cpp -std=c++11 -o GPIOTestApplication

int main(int argc, char *argv[])
{
//Arrays to hold command line input parameters
unsigned int DIRECTION_ARRAY[MAX_GPIO_PINS];
unsigned int VALUE_ARRAY[MAX_GPIO_PINS];

//Example using 3 General Purpose Input/Output (GPIO) pins - 2 Output and 1 Input
unsigned int NUMBER_OF_GPIO_PINS = 3;
JetsonGPIO K1_GPIO_Pin[NUMBER_OF_GPIO_PINS];
K1_GPIO_Pin[0] = JetsonGPIO(GPIO_PU0, OUTPUT_PIN, LOW);
K1_GPIO_Pin[1] = JetsonGPIO(GPIO_PU1, OUTPUT_PIN, LOW);
K1_GPIO_Pin[2] = JetsonGPIO(GPIO_PU2, INPUT_PIN, LOW);

//Command line input error parsing
if(argc < 4){
printf("Usage: %s n DIRECTION_ARRAY[n] VALUE_ARRAY[n]\n", argv[0]);
printf("N: Number of GPIO pins to create (max=%d)\n", MAX_GPIO_PINS);
printf("DIRECTION_ARRAY[%d]: Array to control direction of pins (INPUT PIN = 0 and OUTPUT PIN =1) \n", MAX_GPIO_PINS);
printf("VALUE_ARRAY[%d]: Array to state of pins (LOW = 0 and HIGH =1) \n\n", MAX_GPIO_PINS);
exit(0);
}

sscanf(argv[1], "%d", &NUMBER_OF_GPIO_PINS);
if(NUMBER_OF_GPIO_PINS > MAX_GPIO_PINS){
printf("ERROR: You tried to create more GPIO pins then possible (MAX = %d) on the NVIDIA K1. \n", MAX_GPIO_PINS);
printf("For the first command line argument please enter an integer less than or equal to %d.\n", MAX_GPIO_PINS);
exit(0);
}

//Parse the direction command line arguments 2 to (2+NUMBER_OF_GPIO_PINS)
for(int i = 0; i < NUMBER_OF_GPIO_PINS; i++){
sscanf(argv[(2+i)], "%d", &DIRECTION_ARRAY[i]);
}

//Parse the value (output pins only) command line arguments (2+2*NUMBER_OF_GPIO_PINS+1) to (2+2*NUMBER_OF_GPIO_PINS+1)
for(int j = 0; j < NUMBER_OF_GPIO_PINS; j++){
sscanf(argv[(2+(2*NUMBER_OF_GPIO_PINS)+1+j)], "%d", &VALUE_ARRAY[j]);
}

//Setup time variables to track Mission Elapsed Time (MET)
time_t now;
struct tm MissionStart;
double elapsedSeconds;

auto start = chrono::high_resolution_clock::now();
time(&now); /* get current time; same as: now = time(NULL) */

MissionStart = *localtime(&now);
MissionStart.tm_hour = 0; MissionStart.tm_min = 0; MissionStart.tm_sec = 0;
MissionStart.tm_mon = 0; MissionStart.tm_mday = 1;

elapsedSeconds = difftime(now,mktime(&MissionStart));
auto elapsed = chrono::high_resolution_clock::now() - start;
long long elapsedMircoSeconds = std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count();


cout << "TEST #1:" << endl;
printf("Mission Elaspe Time (MET) rising edge TRIGGER timeStamp (i.e Month-MonthDay-Hour-Minutes-Seconds-MilliSeconds) = %d-%d-%d-%d-%f-",
MissionStart.tm_mon, MissionStart.tm_mday, MissionStart.tm_hour, MissionStart.tm_min, elapsedSeconds);
cout << elapsedMircoSeconds << endl;

K1_GPIO_Pin[0].WritePinState(HIGH); //Set trigger pin high


printf("Mission Elaspe Time (MET) EXPOSURE timeStamp (i.e Month-MonthDay-Hour-Minutes-Seconds-MilliSeconds) = %d-%d-%d-%d-%f-",
MissionStart.tm_mon, MissionStart.tm_mday, MissionStart.tm_hour, MissionStart.tm_min, elapsedSeconds);
cout << elapsedMircoSeconds << endl;

//Toggle exposure pin at 50% duty cycle with period of 32 millisecons
K1_GPIO_Pin[1].WritePinState(HIGH);
usleep(16000);
K1_GPIO_Pin[1].WritePinState(LOW);
usleep(16000);
K1_GPIO_Pin[1].WritePinState(HIGH);

cout << "TEST #2:" << endl;
unsigned int testInputPinState = K1_GPIO_Pin[2].ReadPinState();
cout << "testInputPinState = " << testInputPinState << endl;

cout << "Test complete! Have a nice day :)" << endl;

}//END MAIN
Loading