1

I'm trying to control an ardafruit trinket pro using SPI.

I have checked the feedback of the SPI on the pi, and get the correct output. (using sudo ./spidev_test -D /dev/spidev0.0)

However, when I connect to the trinket I get no data.

When I connect a voltmeter to the sclk pin on the GPIO header, I dont see any voltage at all.

When I connect a voltmeter to the sclk pin on the trinket (when its in master mode) I see a changing voltage, pulsing in time with the clock.

How do I get the sclk pin to output the correct voltage?

I have the MISO, MOSI and SCLK pins on the pi (version B) connected to pins 11, 12 and 13 on the trinket pro.

EDIT:

this code works - if I am returning simple data (like a counter) from the trinket, can't get more complex data to work (such as the input from an analog pin)

import RPi.GPIO as GPIO import spidev import time GPIO.setmode(GPIO.BCM) SPIMOSI=10 SPIMISO=9 SPICLK=11 GPIO.setup(SPIMOSI, GPIO.OUT) GPIO.setup(SPIMISO, GPIO.IN) GPIO.setup(SPICLK, GPIO.OUT) GPIO.setmode(GPIO.BCM) def sendBits(data, numBits): data <<= (8 - numBits) for bit in range(numBits): if(data & (0x01 << bit)): GPIO.output(SPIMOSI, True) else: GPIO.output(SPIMOSI, False) GPIO.output(SPICLK, True) GPIO.output(SPICLK, False) def recvBits(numBits): '''Receives arbitrary number of bits''' retVal = 0 for bit in range(numBits): GPIO.output(SPICLK, True) GPIO.output(SPICLK, False) retVal <<= 1 if (GPIO.input(SPIMISO)): retVal |= 0x1 return (retVal/2) i=0 while True: sendBits(i, 8) print recvBits(8) i=i+1 time.sleep(1)

  • Could you edit your post to give details as follows? Generally you would use software to write to the Pi's SPI peripheral. I guess you are using the software incorrectly or your wiring is incorrect. If you give details of both it may be helpful. How have you checked the "feedback of the SPI on the Pi"? – joan Jan 4 '15 at 9:28
  • @joan added as requested – Zack Newsham Jan 4 '15 at 9:42
  • Thanks. It may be as simple as also adding a ground connection (if you haven't). You haven't mentioned which software you run on the Pi to access the SPI peripheral (to talk to the trinket). I don't know if you can use spidev_test to request data, – joan Jan 4 '15 at 9:54
  • Looking at the trinket it is a 5V device. You will need to use a voltage divider between MISO and the trinket to cut the Arduino 5V output to a Pi gpio safe 3V3. – joan Jan 4 '15 at 10:07
  • @joan I had been using the wiringpi libraries, and somethign called spidev - with no success. I have had some success with writing a python script (in edit) to manually switch the clock, and data I can get it to return a counter, but no reliable data from the analog pins - I think maybe I'm not reading in the right number of bits – Zack Newsham Jan 4 '15 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.