Score:1

can I install wiring pi libraries on my desktop linux PC?

au flag
j0h

I have a project I'm working on, that will eventually be a raspberry pi running Ubuntu also, but right now I just want to write code that includes wiringPi.h, and wiringSerial.h I tried installing wiringpi sudo apt-get install wiringpi, but this did not evidently include the C/C++ libraries for wiringpi.

how can I get the wiringpi C/C++ libraries installed on my ubuntu desktop? the only hardware I am using is a serial port, there shouldn't be any issues with available GPIO.

I am using Ubuntu 20.04 focal

hr flag
https://packages.ubuntu.com/focal/libwiringpi-dev
Score:1
au flag
j0h

It was steel drivers comment, that solved it. sudo apt-get install libwiringpi-dev

There are some issues with libwiringpi-dev. You don't want to call wiringPiSetup(); you'll probably get

Oops: Unable to determine board revision from /proc/device-tree/system/linux,revision
or from /proc/cpuinfo
 -> No "Hardware" line
 ->  You'd best google the error to find out why.

which the reason is you're using a non arm based CPU,and the file its looking at isn't formatted the way it expects. fortunately I don't require any of that, I just wanted to use the simple serial port library.

I also had trouble with sending data via serialPuts(), but I don't need to do the handshaking.. I guess.

This is a little project that reads an Arduino uno with 2 potentiometers and a button, the goal is to use the pots to draw pictures on a screen, or in an image...

#include <iostream>
#include <stdio.h>
#include <unistd.h>       //read function
#include <string.h>
#include <wiringSerial.h> //simple serial port library

using namespace std;
//compiled with g++ -Wall -o readSerial   readSerial.cpp -lwiringPi

int main(int argc, char ** argv)
{
    const char *SensorPort = "/dev/ttyACM0"; //Serial Device Address
     
    int levelSensor = serialOpen(SensorPort, 9600);
    //serialPuts(levelSensor, "1"); //Send command to the serial device

    while (1){
        char buffer[100];
        ssize_t length = read(levelSensor, &buffer, sizeof(buffer));
        if (length == -1){
            cerr << "Error reading from serial port" << endl;
            break;
        }
        else if (length == 0){
            cerr << "No more data" << endl;
            break;
        }else{
            buffer[length] = '\0';
            cout << buffer; //Read serial data
        }
    }

    return 0;
}

the data being sent via the Arduino is via this code:

    /*EtchaSketch
     * 2 pots, X,Y, increment
     * 
     * add a button to delete this shtuff
     * This program communicates on the serial port, to a separate program that handles the drawing of received coordinates (pot values).  
    */
    
    int potX = A0;    
    int potY = A1;    
    int sensorValX = 0;  
    int sensorValY = 0;  
    int del = 1;       //a button on pin 1 for deleting drawn content 
    int delbutton = 0;
    void setup() {
        Serial.begin(9600);
        pinMode(del, INPUT);
    }

   void loop() {
      // read the value from the pots:
      if(digitalRead(del) == HIGH ){
          delbutton=1;
          }else{
              delbutton=0;
          }   
      sensorValX = analogRead(potX);
      sensorValY = analogRead(potY);
      Serial.print(sensorValX);
      Serial.print(",");
      Serial.print(sensorValY);
      Serial.print(",");
      Serial.println(delbutton);
      delay(1000);
      }

and here it is working good enough to go into the parsing / drawing program Reading serial with wiringpi wiringSerial.h

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.