Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Raspberry Pi 3 and SPI interfacing issue

Status
Not open for further replies.

kanchana 29

Newbie level 4
Joined
Sep 14, 2015
Messages
6
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,352
I am using Raspberry pi 3 and have done PyQt4 programming and created the GUI. I am trying to write data through SPI to the pic microcontroller and i was able to send it by defining the values in the code in a list format. But i am unable to send the data from the GUI. I have included all the required Spidev tools and i am giving spi.xfer() command to write the data. But when i click on send button the whole gui just closes on its own. Can i know how to write the values in a list or string format directly from the GUI?
 

Hi,

most probably the problem can be found in your code.

--> post your code.

Klaus
 

here is the code snippet:


Code Python - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /usr/bin/env python
# -*- coding: utf-8 -*-
 
import sys
import time
import serial
import spidev
from PyQt4 import QtGui, QtCore
from PyQt4 import uic
 
uifile_2 = 'sampi.ui'
form_2, base_2 = uic.loadUiType(uifile_2)
 
spi = spidev.SpiDev()
spi.open(0,1)
 
class Simulation(base_2,form_2):
 
     def __init__(self):
          super(base_2,self).__init__()
          self.setupUi(self)
          self.pushButton.clicked.connect(self.add_values)
 
 
     def add_values(self):
          sumed = int(self.lineEdit.text()) + int(self.lineEdit_3.text())
          self.lineEdit_4.setText(str(sumed))
          spi.xfer2(sumed)
          print 'run'
 
spi.close()

 
Last edited by a moderator:

As that file is being read in, the Python interpreter will be executing the lines 14 and 15 which defines and assigns the 'spi' variable, compiling and saving away for later use the class defined from line 17 and then executing line 31 which closes the 'spi' variable. You are not doing anything in between with the 'spi' variable that you create in line 14. Even if you later have executable code that does something with the 'Simulation' class, the 'spi'variable will be long gone.
Further, the class use of the 'spi' variable will be local to the class and not refer to the outer 'spi' variable.
Susan
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top