Comments (9)
Hi @dammianhr,
may I ask what are you using integrated? It needs for ADC MCP3008 / MCP3004 for analog input?
If so, you should download the entire addons, there is now a MCP class for ADC management.
if it is other integrated, give me the datasheet, SPI currently the situation is a little confused, there are two SPI classes and I have to decide to eliminate a short it.
I can help out.
good day
from ofxgpio.
hi! @kashimAstro
I'm trying to run this module:
http://www.hoperf.com/rf_transceiver/lora/RFM95W.html
i have the same error with the module plugged and unplugged
this is my code
`
void ofApp::setup(){
/* cs = new GPIO("8");
cs->export_gpio();
cs->setdir_gpio("out");*/
// spi.setup("/dev/spidev0.0",SPI_MODE_0, 1000000, 8);
d = new unsigned char[2];
//d[0] = (RH_RF95_REG_01_OP_MODE | RH_SPI_WRITE_MASK);
//d[1] = (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE);
d[0] = 1;
d[1] = 0;
int e = spi.spiWriteRead(d,2);
cout << "read/write status: " << e << endl;
//spi.readWrite(d);
/*
//unsigned char e*;
e = new unsigned char[1];
e[0] = RH_RF95_REG_01_OP_MODE;
spi.spiWriteRead(e,1);
cout << "The Result is: " << e << endl;
*/
}
`
from ofxgpio.
-
You have enabled SPI? You can be done easily with the command:
sudo raspi-config -> Advanced Options -> SPI
-
After enabling SPI verify loading the module with:
lsmod | grep spi
and the creation of the device with the command:
ls /dev/spi*
-
controls which PIN SPI you used, raspberry has two integrated SPI interfaces:
P1-24 CE0 /dev/spidev0.0
P1-26 CE1 /dev/spidev0.1
according to the PIN used, adjust the first parameter of: spi.setup("?",mode,speed,bits);
I have not read the datasheet, checks the SPI speed supported by the module.
hello
Dario
from ofxgpio.
i get this
lsmod | grep spi
spi_bcm2835 8032 0
ls /dev/spi*
/dev/spidev0.0 /dev/spidev0.1
i use /dev/spidev0.0.
i test it in python and work fine!
from ofxgpio.
Hi @dammianhr,
pass me the python code.
from ofxgpio.
import spidev
spi = spidev.SpiDev()
spi.open(0,0)
to_send = [(0x01 | 0x80),(0x00 | 0x80)]
spi.writebytes(to_send)
to_read = [0x01]
spi.writebytes(to_read)
recived = spi.readbytes(0)
if recived == [(0x00 | 0x80)]:
print "lora mode on!\n"
print recived
from ofxgpio.
Hi @dammianhr,
try using the SPI2 class, right now I can not verify this code work, try to see if it works.
#include "ofMain.h"
#include "ofxGPIO.h"
class ofApp : public ofBaseApp{
public:
SPI2 spi;
void setup(){
int channel = 0;
spi.setup(channel,1000000);
char data[2];
data[0] = (0x01 | 0x80);
data[1] = (0x00 | 0x80);
char *p = data;
if( spi.readWrite(channel,p,sizeof(data)) )
{
ofLog()<<"Send Request OK!";
}
}
};
int main()
{
ofSetupOpenGL(1024,768, OF_WINDOW);
ofRunApp( new ofApp() );
}
Ciao
from ofxgpio.
hi @kashimAstro !
thanks for your help,
I did several tests and found that my problem was a rare performance of the CS pin .
In python i defined a new pin CS and works well , but not so with ofxGPIO
python code:
import spidev
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
GPIO.output(24,True)
GPIO.output(22,False)
time.sleep(0.5)
GPIO.output(22, True)
spi = spidev.SpiDev()
spi.open(0,0)
spi.bits_per_word = 8
spi.mode = 0
spi.max_speed_hz = 3000000
to_send = [(0x01 | 0x80), (0x00 | 0x80)]
GPIO.output(24,False)
spi.writebytes(to_send)
GPIO.output(24,True)
time.sleep(0.01)
GPIO.output(24,False)
to_read = [0x01]
spi.writebytes(to_read)
recived = spi.readbytes(0)
GPIO.output(24,True)
if recived == [(0x00 | 0x80)]:
print "lora mode on!\n"
print "OP_MODE: ",BytesToHex(recived) , "bin: ", recived
OF code:
#include "ofApp.h"
#define RH_SPI_WRITE_MASK 0x80
#define RH_RF95_REG_01_OP_MODE 0x01
#define RH_RF95_MODE_SLEEP 0x00
#define RH_RF95_LONG_RANGE_MODE 0x80
//--------------------------------------------------------------
void ofApp::setup(){
int ch = 0;
cs = new GPIO("24");
cs->export_gpio();
cs->setdir_gpio("out");
cs->setval_gpio("1");
rst = new GPIO("22");
rst->export_gpio();
rst->setdir_gpio("out");
rst->setval_gpio("0");
usleep(500000);
rst->setval_gpio("1");
// usleep(50000);
spi.setup(ch, 3000000);
spi.spiMode = SPI_MODE_0;
// spi.spiDelay = 10000;
uint8_t f[2];
f[0] = (RH_RF95_REG_01_OP_MODE | RH_SPI_WRITE_MASK);
f[1] = (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE);
cs->setval_gpio("0");
usleep(50000);
int e = spi.readWrite(ch, f, sizeof(f));
// usleep(10000);
cs->setval_gpio("1");
usleep(10000);
if(e) cout << "write ok: " << endl;
uint8_t r[1];
r[0] = RH_RF95_REG_01_OP_MODE;
cs->setval_gpio("0");
usleep(50000);
e = spi.readWrite(ch, r, sizeof(r));
// usleep(50000);
cs->setval_gpio("1");
usleep(10000);
if(e) cout << "write/read ok: " << endl;
cout << "The Result is: " << int(r[0]) << endl;
usleep(500000);
cs->setval_gpio("0");
rst->setval_gpio("0");
cs->unexport_gpio();
rst->unexport_gpio();
close(spi.getFD(ch));
}
from ofxgpio.
Hi @dammianhr,
Maybe I understand the problem, you are using the wrong GPIO numbering, python libraries maintain an internal map of the pin that ofxGPIO do not.
for the execution of the ofxGPIO pins you have to use internal numbers, look at the following image:
check patch: "new GPIO("number pin")"
#include "ofMain.h"
#include "ofxGPIO.h"
#define RH_SPI_WRITE_MASK 0x80
#define RH_RF95_REG_01_OP_MODE 0x01
#define RH_RF95_MODE_SLEEP 0x00
#define RH_RF95_LONG_RANGE_MODE 0x80
class ofApp : public ofBaseApp{
public:
GPIO *cs;
GPIO *rst;
SPI2 spi;
void setup(){
int ch = 0;
cs = new GPIO("18"); //GPIO24
cs->export_gpio();
cs->setdir_gpio("out");
cs->setval_gpio("1");
rst = new GPIO("15"); //GPIO22
rst->export_gpio();
rst->setdir_gpio("out");
rst->setval_gpio("0");
usleep(500000);
rst->setval_gpio("1");
// usleep(50000);
spi.setup(ch, 3000000);
spi.spiMode = SPI_MODE_0;
// spi.spiDelay = 10000;
uint8_t f[2];
f[0] = (RH_RF95_REG_01_OP_MODE | RH_SPI_WRITE_MASK);
f[1] = (RH_RF95_MODE_SLEEP | RH_RF95_LONG_RANGE_MODE);
cs->setval_gpio("0");
usleep(50000);
int e = spi.readWrite(ch, f, sizeof(f));
// usleep(10000);
cs->setval_gpio("1");
usleep(10000);
if(e) cout << "write ok: " << endl;
uint8_t r[1];
r[0] = RH_RF95_REG_01_OP_MODE;
cs->setval_gpio("0");
usleep(50000);
e = spi.readWrite(ch, r, sizeof(r));
// usleep(50000);
cs->setval_gpio("1");
usleep(10000);
if(e) cout << "write/read ok: " << endl;
cout << "The Result is: " << int(r[0]) << endl;
usleep(500000);
cs->setval_gpio("0");
rst->setval_gpio("0");
cs->unexport_gpio();
rst->unexport_gpio();
close(spi.getFD(ch));
}
};
int main( ){
ofSetupOpenGL(1024,768, OF_WINDOW);
ofRunApp( new ofApp());
}
from ofxgpio.
Related Issues (20)
- ADS1015 GPIO HOT 1
- Problem example-i2c-scanner HOT 1
- Can't compare ofstream or ifstream to int in gpio.cpp HOT 4
- example-apa102-ledstrip not lighting leds with Stretch HOT 5
- Use SPI1 for APA102 HOT 5
- 12c examples HOT 9
- Gpio io HOT 5
- Orange Pi 4G IOT HOT 2
- Cannot make SPI work HOT 2
- unable to set direction of gpio HOT 1
- Setting pull up resistors HOT 7
- how do i add ofxGPIO to an existing project? HOT 1
- servo example on rpi 2 - no movement HOT 1
- for Asus TinkerBoard HOT 1
- OPERATION FAILED: Unable to set direction of GPIO4 - openFrameworks not working HOT 2
- Adapting read-write example to distance sensor HOT 5
- using spi1 with MCP
- Issues with using input and output and startup.
- doesnt seems to work with RPi5 Bookworm 0F12.0 arch64 HOT 2
- error open frameworks compiling with window HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ofxgpio.