Quantcast
Channel: Recent Questions - Raspberry Pi Stack Exchange
Viewing all 50864 articles
Browse latest View live

Pi-Hole with two gateways?

$
0
0

Heres my problem. I have a Raspberrypi running pi-hole through router a. I have a second router running openvpn as a tunnel, router "b". I would like to have the pi-hole ad-protect both networks.

Router "a" is 192.168.1.1 and the router "b" is 192.168.2.1

any help would be great.


Running SDL app via RealVNC with Direct Capture enabled does not accept Keyboard input

$
0
0

I am trying to run and SDL hardware-accelerated app, PICO,-8 over VNC, and thanks to this community I am making progress!

One solution is to use RealVNC with the experimental DirectCapture feature enabled. When I do this, PICO-8 launches, but the app does not respond to keyboard commands at all.

How can I send keyboard commands to PICO-8 when using the DirectCapture feature?

Retrieving time without NTP on IoT core

$
0
0

I have an interesting issue. The university I am working at does not allow NTP packets to go through their network, so the basic timing of the Raspberry pi's is completely off, making a connection or ping to them impossible. Is there any work around through the command line on the windows 10 IoT core that I could use to set the time and date? When I try to hard set the date as "date 05/12/2018" the command line returns 'A required privilege is not held by the client'. Any ideas?

vcgencmd in buildroot

$
0
0

I am using buildroot to create a custom os for my raspberry pi. I would like to use the vcgencmd command, but I am unable to find the package that includes these tools. I have tried searching the internet and found that it could be part of VideoCore (which I also cannot find), raspberrypi-firmware (also not present).

So my question is: how to I include the vcgencmd tools in a custom build? What is the package name?

Running a Python Telegram bot at startup and 24/7

$
0
0

I would like to use my Raspberrry Pi (Raspbian Stretch) for running a Telegram bot.

I already wrote the script and it works perfectly, when run in the 'Thonny Python IDE', because there it doesn't terminate after running it.

When I edit my /etc/rc.local via

sudo nano /etc/rc.local

to say

sudo python3 /home/pi/Desktop/bot.py &
exit 0

I'm not quite sure, if the script even executes correctly, because I do not get any response in Telegram.

My script looks like this:

import telepot
from telepot.loop import MessageLoop
import sys

# Logic
def handle(msg):
    content_type, chat_type, chat_id = telepot.glance(msg)

    if str(chat_id) not in open('/home/pi/Desktop/blacklist.txt').read():
        command = msg['text']
        if str(chat_id) in open('/home/pi/Desktop/whitelist.txt').read():            
            print("user: '%d'" % chat_id + ", command: '%s'" % command)

            if command == 'test':
                bot.sendMessage(chat_id, 'Test successful.')
            elif '/check' in command:
                check_id = command.split()
                if str(check_id[1]) in open('/home/pi/Desktop/blacklist.txt').read():
                    bot.sendMessage(chat_id, "Unauthorized user detected.")
                else:
                    bot.sendMessage(chat_id, "No database entry for user '%s'." % check_id[1])
            elif command == '/start':
                bot.sendMessage(chat_id, 'Welcome back, <master_name>.')

        else:
            bot.sendMessage(<master_id>, "Unauthorized access by user '%d'." % chat_id)
            print("user: '%d'" % chat_id + ", command: '%s'" % command)

            file = open('/home/pi/Desktop/blacklist.txt', 'a')
            print(chat_id, file=file)
            file.close()


# Setup
bot = telepot.Bot('<bot_token>')
MessageLoop(bot, handle).run_as_thread()

As you can see, I'm using the Telepot API and MessageLoop, which at least in Thonny, correctly loops my script. Also, this is just the skeleton for Telegram bot as of now.

I searched for solutions via Google, StackOverflow, and the Raspberry Pi StackExchange, but couldn't find a solution to my problem.

Pi-hole will not connect

$
0
0

I am trying to set up my Raspberry Pi as a DNS blocker on my network. but whenever I try to add the ip address and password, I get the prompt "It only works with version 3." Or when I mess around with other settings, a "Cannot connect"

I verified that pi-hole API Version is 3 and using a Raspberry Pi 3B I'm running Raspbian version 9 and updated debian version to 9.6

My raspberry pi can ping the devices on the network. The only thing I can think of is that for my apartment complex internet, DNS server IP addresses get filled out in my internet settings and I had to use that address for DNS to allow my raspberry pi to connect outside the network.

Host MP3 streaming website on raspberry pi

$
0
0

I (as I am sure most people do) have loads of MP3s and CDs from pre Spotify days (other services are available). In particular I have quite a few that aren't on Spotify. So I have decided that I would like to have a convenient way to listen to them.

Does any one know of any software that exists that would let me store the MP3s on the raspberry pi (or an external harddrive attached to the pi), and then stream the MP3s from the pi to my phone (via an android app or a website hosted on the pi, so that the audio comes out of my phone).

I would also be quite happy to write the software myself, in which case I would like some advice about the best architecture. I am thinking something like a ruby on rails site (I say ruby on rails as I have used it very briefly before) + database, in which the MP3s are exposed as HTML audio elements. Is there something better to expose them as? Is there a clever way to put all of the MP3s into the database? Is there a better framework to use (nodejs? Mongodb?)? Is there a way to just expose the file structure in which the MP3s are stored?

Thanks!

Raspberry Pi Multiple I2C Busses

$
0
0

EDIT: Other people I've talked to and one poster here (since deleted) have said that they have the same issue while going through the Instructables tutorial to set up multiple I2C busses. There are also multiple comments on the Instructables describing the same issue. So something is wrong with the tutorial. As of now, I can't find any other tutorials explaining how to set up multiple I2C busses on the Raspberry Pi.


I am trying to connect multiple Vl6180x sensors to my Raspberry Pi 3. The addresses of these sensors are 0x29 (unchangeable) so unless I use a mux, I have to set up multiple I2C busses. I followed the instructions detailed in this tutorial to do so, but when I run "sudo i2cdetect -y 3" it just checks the addresses really slowly and does not find anything on 0x29. Yes, I connected SDA to 23 and SCL to 24. Yes, I tested it on bus 1 and it worked. I am also using 2.2k pullup resistors on both sda and scl. I2C is not blacklisted and here is my config file:

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835) dtparam=audio=on
# --- added by adafruit-pitft-helper Wed Apr 24 16:27:14 HDT 2019 ---
dtparam=spi=on
dtparam=i2c1=on
dtparam=i2c_arm=on
dtoverlay=pitft28-resistive,rotate=90,speed=64000000,fps=30
# --- end adafruit-pitft-helper Wed Apr 24 16:27:14 HDT 2019 ---
enable_uart=1

dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=2,i2c_gpio_sda=23,i2c_gpio_scl=24

dtoverlay=i2c-gpio,bus=4,i2c_gpio_delay_us=2,i2c_gpio_sda=17,i2c_gpio_scl=27

Here is a picture of the sensor on i2c bus 1, and the address is properly detected:

enter image description here

enter image description here

And here is a picture of the sensor connected to my created i2c bus 3 (SDA=23, SCL=24):

enter image description here

So why isn't this working?


EDIT: The device is detected on I2C bus 4:

pi@raspberrypi:~ $ i2cdetect -y 3
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- ^C
pi@raspberrypi:~ $ i2cdetect -y 4
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- 29 -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --                         

And here is the output of "i2cdetect -l":

pi@raspberrypi:~ $ i2cdetect -l
i2c-3   i2c         i2c@4                               I2C adapter
i2c-1   i2c         bcm2835 I2C adapter                 I2C adapter
i2c-4   i2c         i2c@3                               I2C adapter

Runtime error A PWM object already exists for this GPIO channel

$
0
0

iam new to raspberry pi and i got an error while a running servo motor in my object detection script i need to run the servo whenever my if condition is true so the same pin run multiple times if condition satisfies i have done giving servoPIN = 22 GPIO.setmode(GPIO.BCM) GPIO.setup(servoPIN, GPIO.OUT) out of the for loop but doesn't work

Here is the part of the code all import functions are given on top of code(full script :https://github.com/aswinr22/waste-model/blob/master/picamera1.py)

for i in range (classes.size):

    if(classes[0][i] == 2 and scores[0][i]>0.5):

      servoPIN = 22
      GPIO.setmode(GPIO.BCM)
      GPIO.setup(servoPIN, GPIO.OUT)
      p = GPIO.PWM(servoPIN, 50)  #this line shows the error
      p.start(2.5) # Initialization
      try:

        p.ChangeDutyCycle(5)
        time.sleep(4)
        p.ChangeDutyCycle(10)
        time.sleep(4)
      except KeyboardInterrupt:
        p.stop()
      except:
          #print ("exception")

    GPIO.cleanup()

output:(motor turns on and immediately showing below error)

Traceback (most recent call last):
  File "Object_detection_picamera.py", line 150, in <module>
    p = GPIO.PWM(servoPIN, 50) # GPIO 17 for PWM with 50Hz
RuntimeError: A PWM object already exists for this GPIO channel

I dont know why this happening please help me

Minecraft Pi on Raspbian Buster

$
0
0

I have a Raspberry Pi B which is running Raspbian Buster (installed through NOOBS). I am trying to run Minecraft on it. I have downloaded the Pi version of Minecraft from the Minecraft website, unzipped it and am running ./minecraft-pi in the mcpi directory. I am getting the following error

./minecraft-pi: error while loading shared libraries: libGLESv2.so: cannot open shared object file: no such file or directory

I have done a bit of Googling and have tried

  • sudo apt-get install libgles2
  • Uninstalling, cleaning, and reinstalling python-pygame
  • Running LD_LIBRARY_PATH=/opt/vc/lib ./minecraft-pi (I have looked in the /opt/vc/lib directory and can see libGLESv2_static.a but no libGLESv2.so)
  • Navigating to the minecraft-pi file in the GUI desktop and choosing execute from the menu

None of the above have worked and I'm now stumped. My LINUX knowledge is still in its infancy so please keep answers simple or with an explanation.

Virtual ethernet interface on Raspbian buster

$
0
0

I need a virtual ethernet interface on a Raspbian Buster.

I read that I have to use /etc/dhcpcd.conf to set the network configuration but I don't understand where to configure the virtual ethernet. I think /etc/dhcpcd.conf but many answers on the internet suggest to modify /etc/network/interface.

How I can configure my second virtual ethernet?

How do I download shellter for Raspbian?

$
0
0

So my question is: How do you download shellter for Raspbian as

sudo apt-get install shellter

does not work. it says package not found.

Or does shellter not exist for the Raspbian I have found nothing on the internet other than for Kali Linux but that doesn't really help. I'm using a Raspberry Pi 3 model B.

PINN no internet connection after hard reset

$
0
0

I have recently installed and configured a new server on my raspberry pi 3B. I used PINN as my bootloader and installed some OSes (Fedberry - an Raspberry Fedora implementation - being the main one). I have configured everything on the bootloader an Fedora itself that I wanted to work.

The pi os working solely as server without display or any other peripherals. I'm connecting to it over SSH or VNC to do some configuring.

Lastly I had to unplug my Raspberry for few hours. After plugging it in again there was no network connection to it (neither ping, ssh nor vnc). I didn't tried looking into it with display for troubleshooting, instead I restarted my router (Fritz Box 7360) and could connect to my Raspberry as everytime before again.

After that my guess was, that it would be something about DHCP configuration on my Raspberry but it seems fine. I tested some configurations like nmcli (Network Manager CLI) and could confirm that services like DHCP are actually working.

I can't find any reason why the raspberry that normally connects to the wired network can't repeat the process after being unplugged and plugged back in. When I reboot through the Fedberry CLI via sudo reboot I have no problems whit connectivity.

I would be glad about some directions about where to look for a solution to the problem. The Firtz Box restart workaround works but it removes the connectivity to the internet to other devices for the reboot time. Besides I imagine there is some solution to this problem that I'm simply missing.

Thanks in Advance.

Edit: When I talk about unplugging it's not about ethernet cable but the power cable to shut down the device.

How to run DNS server on raspberry repeater using systemd network

Unwanted extern hard disk 's name changes

$
0
0

I try to make my external hard disk a permanant one on a Raspberry Pi 3 b+. After editing the fstab file, It was working. However I don't know why but some times the hard disk which name is DiskExt/ change to DiskExt_/. The OS that is install on the Raspberry is OSMC.


Stepper motor vibrates, does not turn

$
0
0

I´m working on a simple project for school now and I have to use a stepper motor, but it doesn´t turn. The LEDs go on, the motor gets hot and the motor vibrates. When I adjust the sleep/function, the vibration pulses go quicker or slower. Yet the motor doesn´t turn. What can I do?

This is the script I use in Python on my Raspberry Pi. I'm not receiving any error.

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
control_pins = [7,11,13,15]
for pin in control_pins:
  GPIO.setup(pin, GPIO.OUT)
  GPIO.output(pin, 0)
halfstep_seq = [
  [1,0,0,0],
  [1,1,0,0],
  [0,1,0,0],
  [0,1,1,0],
  [0,0,1,0],
  [0,0,1,1],
  [0,0,0,1],
  [1,0,0,1],
]
for i in range(512):
  for halfstep in range(8):
    for pin in range(4):
      GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])
    time.sleep(0.001)
GPIO.cleanup()
GPIO BOARD pin goes to the minus
pin 4 to plus
ln4 to 17
ln3 to 15
ln2 to 13
ln1 to 7

The stepper motor is ROHS 28BYJ-48 5Voltage DC

Setting up the second PWM channel from kernel module not working on RPI 3 model B+

$
0
0

I'm trying to set up both PWM channels (PMW0 and PMW1) on my Raspberry Pi 3 Model B+ from my kernel module. I've successfully set up channel 0 with the desired frequency and variable duty cycle and I'm getting the expected output on GPIO 12 and 18 pins. However, doing the same configuration steps for channel 1, I cannot get any output from GPIO 13 or 19 pins. I thought that maybe only one channel can work at a time, but disabling channel 0 and only setting up channel 1 didn't change anything. Here is my kernel module code:

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/uaccess.h>
#include <linux/ioctl.h> 

MODULE_LICENSE("Dual BSD/GPL");

/* GPIO registers base address. */
#define BCM2708_PERI_BASE   (0x3F000000)
#define GPIO_BASE           (BCM2708_PERI_BASE + 0x200000)

/* GPIO registers */
struct S_GPIO_REGS
{
      uint32_t GPFSEL[6];
      uint32_t Reserved0;
      uint32_t GPSET[2];
      uint32_t Reserved1;
      uint32_t GPCLR[2];
      uint32_t Reserved2;
      uint32_t GPLEV[2];
      uint32_t Reserved3;
      uint32_t GPEDS[2];
      uint32_t Reserved4;
      uint32_t GPREN[2];
      uint32_t Reserved5;
      uint32_t GPFEN[2];
      uint32_t Reserved6;
      uint32_t GPHEN[2];
      uint32_t Reserved7;
      uint32_t GPLEN[2];
      uint32_t Reserved8;
      uint32_t GPAREN[2];
      uint32_t Reserved9;
      uint32_t GPAFEN[2];
      uint32_t Reserved10;
      uint32_t GPPUD;
      uint32_t GPPUDCLK[2];
      uint32_t Reserved11[4];
} *gpio_regs;

/* GPIO pins available on connector p1 */
typedef enum {GPIO_02 = 2,
              GPIO_03 = 3,
              GPIO_04 = 4,
              GPIO_05 = 5,
              GPIO_06 = 6,
              GPIO_07 = 7,
              GPIO_08 = 8,
              GPIO_09 = 9,
              GPIO_10 = 10,
              GPIO_11 = 11,
              GPIO_12 = 12,
              GPIO_13 = 13,
              GPIO_14 = 14,
              GPIO_15 = 15,
              GPIO_16 = 16,
              GPIO_17 = 17,
              GPIO_18 = 18,
              GPIO_19 = 19,
              GPIO_20 = 20,
              GPIO_21 = 21,
              GPIO_22 = 22,
              GPIO_23 = 23,
              GPIO_24 = 24,
              GPIO_25 = 25,
              GPIO_26 = 26,
              GPIO_27 = 27} GPIO;

/* GPIO Pin Pull-up/down */
typedef enum {PULL_NONE = 0,
              PULL_DOWN = 1,
              PULL_UP = 2} PUD;

/* GPIO Pin Alternative Function selection */
// By default GPIO pin is being used as an INPUT
typedef enum {GPIO_INPUT     = 0b000,
              GPIO_OUTPUT    = 0b001,
              GPIO_ALT_FUNC0 = 0b100,
              GPIO_ALT_FUNC1 = 0b101,
              GPIO_ALT_FUNC2 = 0b110,
              GPIO_ALT_FUNC3 = 0b111,
              GPIO_ALT_FUNC4 = 0b011,
              GPIO_ALT_FUNC5 = 0b010,} FSEL;

/*
 * SetGPIOFunction function
 *  Parameters:
 *   pin   - number of GPIO pin;
 *
 *   code  - alternate function code to which the GPIO pin is to be set
 *  Operation:
 *   Based on the specified GPIO pin number and function code, sets the GPIO pin to
 *   operate in the desired function. Each of the GPIO pins has at least two alternative functions.
 */
void SetGPIOFunction(GPIO pin, FSEL code)
{
    int regIndex = pin / 10;
    int bit = (pin % 10) * 3;

    unsigned oldValue = gpio_regs->GPFSEL[regIndex];
    unsigned mask = 0b111 << bit;

    gpio_regs->GPFSEL[regIndex] = (oldValue & ~mask) | ((code << bit) & mask);
}

/* PWM registers base address */
#define PWM_BASE (BCM2708_PERI_BASE + 0x20C000)
#define PWM_CLK_BASE (BCM2708_PERI_BASE + 0x101000)
#define PWMCLK_CTL  40
#define PWMCLK_DIV  41

/* PWM registers */
struct S_PWM_REGS
{
    uint32_t CTL;
    uint32_t STA;
    uint32_t DMAC;
    uint32_t reserved0;
    uint32_t RNG1;
    uint32_t DAT1;
    uint32_t FIF1;
    uint32_t reserved1;
    uint32_t RNG2;
    uint32_t DAT2;
} *pwm_regs;

struct S_PWM_CTL {
    unsigned PWEN1 : 1;
    unsigned MODE1 : 1;
    unsigned RPTL1 : 1;
    unsigned SBIT1 : 1;
    unsigned POLA1 : 1;
    unsigned USEF1 : 1;
    unsigned CLRF1 : 1;
    unsigned MSEN1 : 1;
    unsigned PWEN2 : 1;
    unsigned MODE2 : 1;
    unsigned RPTL2 : 1;
    unsigned SBIT2 : 1;
    unsigned POLA2 : 1;
    unsigned USEF2 : 1;
    unsigned Reserved1 : 1;
    unsigned MSEN2 : 1;
    unsigned Reserved2 : 16;
} *pwm_ctl;

struct S_PWM_STA {
    unsigned FULL1 : 1;
    unsigned EMPT1 : 1;
    unsigned WERR1 : 1;
    unsigned RERR1 : 1;
    unsigned GAPO1 : 1;
    unsigned GAPO2 : 1;
    unsigned GAPO3 : 1;
    unsigned GAPO4 : 1;
    unsigned BERR : 1;
    unsigned STA1 : 1;
    unsigned STA2 : 1;
    unsigned STA3 : 1;
    unsigned STA4 : 1;
    unsigned Reserved : 19;
} *pwm_sta;

volatile unsigned int *pwm_clk_regs; // Holds the address of PWM CLK registers

/*
 * Establish PWM frequency function
 *  Parameters:
 *   divi   - integer part of divisor.
 *  Operation:
 *   Based on the passed GPIO pin number and function code, sets the GPIO pin to
 *   operate the desired function. Each of the GPIO pins has at least two alternative functions.
 */
void pwm_frequency(uint32_t divi) {

    // Kill the clock
    *(pwm_clk_regs+PWMCLK_CTL) = 0x5A000020;

    // Disable PWM
    pwm_ctl->PWEN1 = 0;
    pwm_ctl->PWEN2 = 0;
    udelay(10);

    // Set the divisor
    *(pwm_clk_regs+PWMCLK_DIV) = 0x5A000000 | (divi << 12);

    // Set source to oscillator and enable clock
    *(pwm_clk_regs+PWMCLK_CTL) = 0x5A000011;
}

void set_up_pwm_channels(void){
    // Channel 1 set-up
    pwm_ctl->MODE1 = 0;
    pwm_ctl->RPTL1 = 0;
    pwm_ctl->SBIT1 = 0;
    pwm_ctl->POLA1 = 0;
    pwm_ctl->USEF1 = 0;
    pwm_ctl->CLRF1 = 1;
    pwm_ctl->MSEN1 = 1;

    // Channel 2 set-up
    pwm_ctl->MODE2 = 0;
    pwm_ctl->RPTL2 = 0;
    pwm_ctl->SBIT2 = 0;
    pwm_ctl->POLA2 = 0;
    pwm_ctl->USEF2 = 0;
    pwm_ctl->MSEN2 = 1;
}

void pwm_ratio_c1(unsigned n, unsigned m) {

    // Disable PWM Channel 1
    pwm_ctl->PWEN1 = 0;

    // Set the PWM Channel 1 Range Register
    pwm_regs->RNG1 = m;
    // Set the PWM Channel 1 Data Register
    pwm_regs->DAT1 = n;

    // Check if PWM Channel 1 is not currently transmitting
    if ( !pwm_sta->STA1 ) {
        if ( pwm_sta->RERR1 ) pwm_sta->RERR1 = 1; // Clear RERR bit if read occured on empty FIFO while channel was transmitting
        if ( pwm_sta->WERR1 ) pwm_sta->WERR1 = 1; // Clear WERR bit if write occured on full FIFO while channel was transmitting
        if ( pwm_sta->BERR ) pwm_sta->BERR = 1; // Clear BERR bit if write to registers via APB occured while channel was transmitting
    }
    udelay(10);

    // Enable PWM Channel 1
    pwm_ctl->PWEN1 = 1;
}

void pwm_ratio_c2(unsigned n, unsigned m) {

    // Disable PWM Channel 2
    pwm_ctl->PWEN2 = 0;

    // Set the PWM Channel 2 Range Register
    pwm_regs->RNG2 = m;
    // Set the PWM Channel 2 Data Register
    pwm_regs->DAT2 = n;

    // Check if PWM Channel 2 is not currently transmitting
    if ( !pwm_sta->STA2 ) {
        if ( pwm_sta->RERR1 ) pwm_sta->RERR1 = 1; // Clear RERR bit if read occured on empty FIFO while channel was transmitting
        if ( pwm_sta->WERR1 ) pwm_sta->WERR1 = 1; // Clear WERR bit if write occured on full FIFO while channel was transmitting
        if ( pwm_sta->BERR ) pwm_sta->BERR = 1; // Clear BERR bit if write to registers via APB occured while channel was transmitting
    }
    udelay(10);

    // Enable PWM Channel 2
    pwm_ctl->PWEN2 = 1;
}


/* Declaration of my_pwm_driver.c functions */
int my_pwm_driver_init(void);
void my_pwm_driver_exit(void);
static int my_pwm_driver_open(struct inode *, struct file *);
static int my_pwm_driver_release(struct inode *, struct file *);
static ssize_t my_pwm_driver_read(struct file *, char *buf, size_t , loff_t *);
static ssize_t my_pwm_driver_write(struct file *, const char *buf, size_t , loff_t *);
static long my_pwm_driver_ioctl(struct file *file, unsigned int cmd, unsigned long arg);

/* Structure that declares my_pwm_driver file operations */
struct file_operations my_pwm_driver_fops =
{
    open            :   my_pwm_driver_open,
    release         :   my_pwm_driver_release,
    read            :   my_pwm_driver_read,
    write           :   my_pwm_driver_write
};

/* Declaration of the init and exit functions. */
module_init(my_pwm_driver_init);
module_exit(my_pwm_driver_exit);

/* Major number. */
int my_pwm_driver_major;


int my_pwm_driver_init(void)
{
    int result = -1;

    printk(KERN_INFO "Inserting my_pwm_driver module..\n");

    /* Registering device. */
    result = register_chrdev(0, "my_pwm_driver", &my_pwm_driver_fops);
    if (result < 0)
    {
        printk(KERN_INFO "my_pwm_driver: cannot obtain major number %d\n", my_pwm_driver_major);
        return result;
    }

    my_pwm_driver_major = result;
    printk(KERN_INFO "my_pwm_driver major number is %d\n", my_pwm_driver_major);

    // Map the GPIO register space from PHYSICAL address space to VIRTUAL address space
    gpio_regs = (struct S_GPIO_REGS *)ioremap(GPIO_BASE, sizeof(struct S_GPIO_REGS));
    if(!gpio_regs)
    {
        result = -ENOMEM;
        goto fail_no_virt_mem;
    }

    // Map the PWM register space from PHYSICAL address space to VIRTUAL address space
    pwm_regs = (struct S_PWM_REGS *)ioremap(PWM_BASE, sizeof(struct S_PWM_REGS));
    if(!pwm_regs)
    {
        result = -ENOMEM;
        goto fail_no_virt_mem;
    }
    pwm_ctl = (struct S_PWM_CTL *) &pwm_regs -> CTL;
    pwm_sta = (struct S_PWM_STA *) &pwm_regs -> STA;

    // Map the PWM Clock register space from PHYSICAL address space to VIRTUAL address space
    pwm_clk_regs = ioremap(PWM_CLK_BASE, 4096);
    if(!pwm_clk_regs)
    {
        result = -ENOMEM;
        goto fail_no_virt_mem;
    }

    // Setting the GPIO pins alternative functions to PWM
    SetGPIOFunction(GPIO_12, GPIO_ALT_FUNC0); // Setting GPIO_12 pin to alternative function 0 - PWM channel 0
    SetGPIOFunction(GPIO_13, GPIO_ALT_FUNC0); // Setting GPIO_13 pin to alternative function 0 - PWM channel 1
    SetGPIOFunction(GPIO_18, GPIO_ALT_FUNC5); // Setting GPIO_18 pin to alternative function 5 - PWM channel 0
    SetGPIOFunction(GPIO_19, GPIO_ALT_FUNC5); // Setting GPIO_19 pin to alternative function 5 - PWM channel 1

    // Set up PWM channels
    set_up_pwm_channels();

    // Setting PWM with approx 1kHz frequency and fine tuning with 0.1% duty cycle step
    // PWM frequency can be calculated with formula pwmFrequency in Hz = 19200000Hz / divi / pwm_range.
    pwm_frequency(19); 
    pwm_ratio_c1(200, 1000);
    pwm_ratio_c2(500, 1000);

    return 0;

fail_no_virt_mem:

    // Unmap the GPIO registers PHYSICAL address space from VIRTUAL memory
    if (gpio_regs)
        iounmap(gpio_regs);
    // Unmap the PWM registers PHYSICAL address space from VIRTUAL memory
    if (pwm_regs)
        iounmap(pwm_regs);
    // Unmap the PWM Clock registers PHYSICAL address space from VIRTUAL memory
    if (pwm_clk_regs)
        iounmap(pwm_clk_regs);

    /* Freeing the major number. */
    unregister_chrdev(my_pwm_driver_major, "my_pwm_driver");

    return result;
}

void my_pwm_driver_exit(void)
{
    // Clearing the GPIO pins - setting to LOW
    gpio_regs->GPCLR[12/32] |= (1 << (12 % 32));
    gpio_regs->GPCLR[13/32] |= (1 << (13 % 32));
    gpio_regs->GPCLR[18/32] |= (1 << (18 % 32));
    gpio_regs->GPCLR[19/32] |= (1 << (19 % 32));

    // Setting the GPIO pins to default function - as INPUT
    SetGPIOFunction(GPIO_12, GPIO_INPUT);
    SetGPIOFunction(GPIO_13, GPIO_INPUT);
    SetGPIOFunction(GPIO_18, GPIO_INPUT);
    SetGPIOFunction(GPIO_19, GPIO_INPUT);

    // Unmap the GPIO registers PHYSICAL address space from VIRTUAL memory
    if (gpio_regs)
        iounmap(gpio_regs);
    // Unmap the PWM registers PHYSICAL address space from VIRTUAL memory
    if (pwm_regs)
        iounmap(pwm_regs);
    // Unmap the PWM Clock registers PHYSICAL address space from VIRTUAL memory
    if (pwm_clk_regs)
        iounmap(pwm_clk_regs);

    printk(KERN_INFO "Removing my_pwm_driver module\n");

    /* Freeing the major number. */
    unregister_chrdev(my_pwm_driver_major, "my_pwm_driver");
}

static int my_pwm_driver_open(struct inode *inode, struct file *filp)
{
    return 0;
}

static int my_pwm_driver_release(struct inode *inode, struct file *filp)
{
    return 0;
}

static ssize_t my_pwm_driver_read(struct file *filp, char *buf, size_t len, loff_t *f_pos)
{
    printk(KERN_ALERT "Sorry, this operation isn't supported.\n");

    return -EPERM; // Operation not permitted error
}

static ssize_t my_pwm_driver_write(struct file *filp, const char *buf, size_t len, loff_t *f_pos)
{
    printk(KERN_ALERT "Sorry, this operation isn't supported.\n");

    return -EPERM; // Operation not permitted error
}

As you can see in the init function, I'm setting the GPIO pins 12 and 13 to alternative function 0 and GPIO pins 18 and 19 to alternative function 5, as described in BCM2835 ARM Peripherials document. However, only pins 12 and 18, which are on channel 0 give me the output. What am I doing wrong?

Edit:

Following this schematic, I connect the oscilloscope probe to GPIO pins 12, 13, 18 and 19. enter image description here

I only get the output from pins 12 and 18, and they're both on channel 0. As we can see, the signals from those pins are both at 20% duty cycle as was configured in the driver. However, I get a flat line on pins 13 and 19, which are on channel 1.

enter image description here

Edit 2:

Testing the GPIO pins levels with monitor.py as suggested by @joan gives the following output:

enter image description here

enter image description here

As we can see, when my driver module is not running, there is some activity on GPIO 29, but I'm not sure where it is located on Raspberry Pi since it's not among the 40 GPIO pins. When I run my module configured only for pins 18 and 19, monitor.py shows activity only on GPIO 18 and 29. When all pins 12, 13, 18 and 19 are configured for PWM, we can see that monitor.py registers only pins 12 and 18 which are on channel 0, apart from GPIO 29, and no change on pins 13 and 19 is detected.

How can I get out of a try function in python? [on hold]

$
0
0

What's up you guys, I'm having problems with the function try and except,what I want to do is: check if connection with internet exists, if so, it sends data by URL, if it isn't, it saves data in a txt file, but the way that I'm doing this uses a time.sleep() to exit of the try condition and I have to check this all the time, I use this to cach datas in real time, so I can´t use a delay or something like that. Someone knows how can I exit of try function without this time.sleep?

while True:
    try:      
       url=urllib.request.urlopen('http://192.168.1.44/openhouse/get_infos.php')
       flag_conectado = 1
    except Exception as exc:
        flag_conectado = 2
    time.sleep(5)
    return(flag_conectado)

I'm using my Pi as a seedbox using Deluge - how would I create torrents to add to the seedbox?

$
0
0

I have some files on my Pi that I would like to upload and seed to a private tracker but I don't know how to go about creating the torrents on the Pi itself. I can access the seedbox through Deluge on my Windows machine, but I don't think I can create the torrents through that, can I? If not, I don't know if there's a GUI version or series of commands in the terminal I need to execute to make the torrents, googling has made me more confused than anything so any help would be appreciated.

Destination host unreachable, Pi not connected to internet

$
0
0

I'm using ssh to connect to the Pi from my MS Windows PC, and I'm using a wired connection to do so. Now the problem is even though my Pi is connected to wifi (which provides internet access), it doesn't seem to be able to connect to the internet. I'm trying to download the sudo apt-get install xrdp to get GUI. However it gives out error "destination host unreachable" as can be seen on the Error message. I tried to ping the Pi from my computer's cmd and it works. So I tried to ping google.com from the pi, but it also gives destination host unreachable error. My Pi is indeed connected to the internet as when I run iwconfig it shows my router's ESSID. Anyone knows how to fix this?

I'm using ssh to connect to the Pi, and I'm using a wired connection to do so. Now the problem is even though my Pi is connected to wifi (which provides internet access)

Error message:

pi@raspberrypi:~ $ sudo apt-get install xrdp
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libglu1-mesa ssl-cert x11-apps x11-session-utils xbitmaps xfonts-75dpi
xfonts-base xfonts-scalable xorg xorg-docs-core xorgxrdp
Suggested packages:
openssl-blacklist mesa-utils xorg-docs x11-xfs-utils guacamole
xrdp-pulseaudio-installer
The following NEW packages will be installed:
libglu1-mesa ssl-cert x11-apps x11-session-utils xbitmaps xfonts-75dpi
xfonts-base xfonts-scalable xorg xorg-docs-core xorgxrdp xrdp
0 upgraded, 12 newly installed, 0 to remove and 119 not upgraded.
Need to get 11.0 MB of archives.
After this operation, 17.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Err:1 http://raspbian.raspberrypi.org/raspbian buster/main armhf libglu1- 
mesa armhf 9.0.0-2.1
Cannot initiate the connection to raspbian.raspberrypi.org:80 
(2a00:1098:0:80:1000:75:0:3). - connect (101: Network is unreachable) Could 
not connect to raspbian.raspberrypi.org:80 (93.93.128.193). - connect (113: 
No route 
to host)
Err:2 http://raspbian.raspberrypi.org/raspbian buster/main armhf ssl-cert 
all 
1.0.39

Ping my Pi from computer's cmd:

C:\Users\Hp>ping 192.168.1.2

Pinging 192.168.1.2 with 32 bytes of data:
Reply from 192.168.1.2: bytes=32 time=1ms TTL=64
Reply from 192.168.1.2: bytes=32 time<1ms TTL=64
Reply from 192.168.1.2: bytes=32 time<1ms TTL=64
Reply from 192.168.1.2: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.1.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms

Ping Google:

pi@raspberrypi:~ $ ping google.com
PING google.com (172.217.168.206) 56(84) bytes of data.
From 192.168.1.2 (192.168.1.2) icmp_seq=1 Destination Host Unreachable
From 192.168.1.2 (192.168.1.2) icmp_seq=2 Destination Host Unreachable
From 192.168.1.2 (192.168.1.2) icmp_seq=3 Destination Host Unreachable
From 192.168.1.2 (192.168.1.2) icmp_seq=4 Destination Host Unreachable
From 192.168.1.2 (192.168.1.2) icmp_seq=5 Destination Host Unreachable
From 192.168.1.2 (192.168.1.2) icmp_seq=6 Destination Host Unreachable
^C
--- google.com ping statistics ---
7 packets transmitted, 0 received, +6 errors, 100% packet loss, time 215ms
pipe 4

EDIT: sudo route -n gives me the following:

pi@raspberrypi:~ $ sudo route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         0.0.0.0         0.0.0.0         U     202    0        0 eth0
0.0.0.0         172.20.10.1     0.0.0.0         UG    303    0        0 wlan0
172.20.10.0     0.0.0.0         255.255.255.240 U     303    0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0

ifconfig wlan0 gives me:

pi@raspberrypi:~ $ ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 172.20.10.10  netmask 255.255.255.240  broadcast 172.20.10.15
    inet6 fe80::9768:9bb9:4b4:143f  prefixlen 64  scopeid 0x20<link>
    ether b8:27:eb:01:00:35  txqueuelen 1000  (Ethernet)
    RX packets 398  bytes 45561 (44.4 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 141  bytes 17153 (16.7 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

and ip addr gives me:

pi@raspberrypi:~ $ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
   valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:54:55:60 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 brd 192.168.1.255 scope global noprefixroute eth0
   valid_lft forever preferred_lft forever
inet6 fe80::3ae0:826b:38ae:2d42/64 scope link
   valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:01:00:35 brd ff:ff:ff:ff:ff:ff
inet 172.20.10.10/28 brd 172.20.10.15 scope global noprefixroute wlan0
   valid_lft forever preferred_lft forever
inet6 fe80::9768:9bb9:4b4:143f/64 scope link
   valid_lft forever preferred_lft forever
Viewing all 50864 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>