jaybee007
Posts: 20
Joined: Thu May 29, 2014 8:49 pm

Re: Guzunty Pi. New users start here.

Tue Jul 15, 2014 2:33 pm

Hi Derek,
Thanks for the speedy reply, I am already using an arduino leo.
I have programmed it as USB controller it works great, but I was wondering if there was an easy way to add analogue because as you stated the pi has none. The cpld can be used as an arduino I just wasn't sure lol.
What would be the easiest way to interface the arduino through the cpld ?
Thanks again

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Tue Jul 15, 2014 3:27 pm

A Leonardo, huh? Yes, you can interface that to the Pi through the CPLD. You wouldn't want to connect it directly to the Pi because it works at 5v.

What I do is to connect the CPLD to the ICSP header on the Arduino. I use the gz_arduino core, which connects the programming signals and the Rx and Tx signals to the Raspberry Pi. See the gz_arduino.rpt file to see which signals go where. You can see it in action here at the bottom of the page:

https://github.com/Guzunty/Pi/wiki/Gallery-of-examples

This allows you to both program and communicate with the Arduino. You talk to it via the /dev/ttyAMA0 on the Pi and you program it using the arduino raspbian package (sudo apt-get arduino). The CPLD is programmed so that it uses the same programming pins as a Gertboard, so you can use Gordon Henderson's excellent tutorials on setting up the environment.

HTH,

Derek
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Tue Jul 15, 2014 6:41 pm

Initial tests show that, as expected, Guzunty is compatible with the new Pi model B+.

I will test more completely in the coming days, but there is no reason to anticipate any problems at this time.

Enjoy your Model B+s :-)
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

jaybee007
Posts: 20
Joined: Thu May 29, 2014 8:49 pm

Re: Guzunty Pi. New users start here.

Tue Jul 15, 2014 8:10 pm

Hi Derek,
Thanks for the reply, I think I misunderstood what the arduino core did lol. I thought that's that the cpld functioned as an arduino once programmed with the core. :shock:
I did say I was a noob.

guzunty wrote:A Leonardo, huh? Yes, you can interface that to the Pi through the CPLD. You wouldn't want to connect it directly to the Pi because it works at 5v.

HTH,

Derek
I plug the leonardo in to the pi via USB, it's recognised as a mouse,keyboard or both, it can be easy programmed with the example sketch in the arduino IDE. And It runs at 3.3v so no need for a logic level convertor. I tried to upload a pic of my current setup but it wouldn't let me for some reason. I plan to swap the standard leo for the Leo pro (the micro version) but it's not arrived yet.

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Tue Jul 15, 2014 9:25 pm

I thought that's that the cpld functioned as an arduino once programmed with the core.
Actually, that is not such a unlikely idea. Larger programmable devices, like the Xilinx Spartan are capable of *being* an Arduino. The XC9572XL in the Guzunty is not that large. (it's also more than 5x less expensive if you should make a mistake and fry the chip).

My reading of the Leonardo spec is that it runs at 5v. See here http://arduino.cc/en/Main/arduinoBoardLeonardo. You therefore shouldn't try to connect any of its signals with the Pi directly. I'm not saying you won't get away with it, but it's way out of spec and you might damage your Pi (and possibly not immediately).

Communicating with it over USB is completely safe, but not very efficient, both in terms of power consumption and performance. I prefer to communicate with the ATMega directly for this reason.

I was thinking of something like this:

https://www.sparkfun.com/products/11113

Very small, light, no USB and pretty inexpensive.

HTH,

Derek
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

jaybee007
Posts: 20
Joined: Thu May 29, 2014 8:49 pm

Re: Guzunty Pi. New users start here.

Wed Jul 16, 2014 6:00 am

Hi Derek,
Thanks again for your speedy reply, I have two of those in the link,but for the life of me I can't get it programmed as a joystick,that's why I ended up going with Leo,it was almost plug and play. But you are right,I do feel like it is drawing a lot of power from the pi.I'm running a 4.3" ssd1963 connected via the guzunty,so power is an issue and the Leo doesn't seem to like being powered from the barrel while its connected to the pi via the usb,it just locks up. So I may well be looking at something like the gert style interface you mentioned earlier .
Thanks for taking the time to help me with this.

Edit: also what other cpld could fit the guzunty ? I wanted a couple more xc9572xl's but I refuse to pay the postage from element 14,and cpc (although they are the same place ) seem to have stopped stocking them.I seen some on digi-key but they wanted £12 pnp lol.I have looked at a few,but I wasn't sure what would work best guzunty board.
Thanks again

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Wed Jul 16, 2014 7:10 am

Confirming correct operation on the model B+ of the following cores:

gz_test, gz_16o8i, gz_lcd

more core to follow, but it's now highly unlikely there will be any issues with the others.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Wed Jul 16, 2014 9:55 am

Edit: also what other cpld could fit the guzunty ? I wanted a couple more xc9572xl's but I refuse to pay the postage from element 14,and cpc (although they are the same place ) seem to have stopped stocking them.I seen some on digi-key but they wanted £12 pnp lol.I have looked at a few,but I wasn't sure what would work best guzunty board.
Thanks again
The xc9536xl-PC44 will fit, but you'd need to rerun the Xilinx Impact tool on all the cores for them to work. Also some of them would not fit due to its having half the number of macrocells. Depends what you need it to do.

The 9572 is the largest CPLD that fits the design. Bigger arrays exist but are only available in QFP package format. I've soldered them, but they need a steady hand and I've lost a few. Most people would not want to try their hand at building their own. Prebuilt boards would have to be sold at a cost that (for many) would not fit with the Rasperry Pi's initial selling price. And if you make a wiring mistake, the whole board is toast whereas with the Guzunty you just lever out the dead chip and put in a new one.

I buy the CPLD's in bulk so the shipping costs don't hurt. I can send you a few at the same price as Farnell but with the standard Guzunty shipping and handling rate, which is for the UK £2.20.

best,

Derek
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

jaybee007
Posts: 20
Joined: Thu May 29, 2014 8:49 pm

Re: Guzunty Pi. New users start here.

Wed Jul 16, 2014 5:39 pm

guzunty wrote:

The 9572 is the largest CPLD that fits the design. Bigger arrays exist but are only available in QFP package format. I've soldered them, but they need a steady hand and I've lost a few. Most people would not want to try their hand at building their own. Prebuilt boards would have to be sold at a cost that (for many) would not fit with the Rasperry Pi's initial selling price. And if you make a wiring mistake, the whole board is toast whereas with the Guzunty you just lever out the dead chip and put in a new one.

I buy the CPLD's in bulk so the shipping costs don't hurt. I can send you a few at the same price as Farnell but with the standard Guzunty shipping and handling rate, which is for the UK £2.20.

best,

Derek
Hi Derek,
I hear exactly what you are saying with regards to the surface mount chips...I wouldn't fancy my chances. I would like to take you up on your kind offer. I have just ordered a 7 inch screen for my model b+ so I was just about to order another full guzunty pi kit and 2 daughter boards. I don't know if you could combine them all together? The pay after delivery I've previously used is really handy too. Thanks once again.

Edit : also have you tried to daisy chain the guzunty ?
Thank you for your patience :)
Last edited by jaybee007 on Wed Jul 16, 2014 5:50 pm, edited 1 time in total.

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Wed Jul 16, 2014 5:45 pm

Sure, you can combine it all together and save some mailing costs. :)
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

jaybee007
Posts: 20
Joined: Thu May 29, 2014 8:49 pm

Re: Guzunty Pi. New users start here.

Wed Jul 16, 2014 5:51 pm

Ok how shall I order it? Will you send me a PayPal invoice? Many thanks once again

ptrav1956
Posts: 7
Joined: Thu Jul 31, 2014 9:31 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 11:35 am

Hi,
I've been trying to get the Guzunty going with the 4s808i core with the aim of controlling the servos in a Phenoptix MeArm. The initial tests on the Guzunty all ran well, and the loading of the core was also successful. However I have problems in getting the servo to respond.

The code I am using to test it is simple .. and in python (run as root so the clock_enable command doesnt generate an error)

Code: Select all

import GZ
import time

def test(a,b):
    GZ.spi_write(a)
    time.sleep(0.1)
    GZ.spi_write(b)
    time.sleep(0.1)

GZ.spi_set_width(2)
GZ.clock_ena(0,50)

test(0,100)
The only response I have had is that enabling the clock changed the position of the servo, but no test command subsequently has had any effect. Is there something I am missing here? The servo input is connected to FB1_2, power and ground to the ground and 5v feed from the Guzunty.

Is it worthwhile sticking a LED onto this pin to see if there is any output? With a max pulse length of 2ms I am not sure I would see anything. If I did this with the outputs to test the operation, would I turn on output 0 with spi_write('0x01') or spi_write('0x80')?

Being a newbie at both Pi and Python, any help would be gratefully appreciated,

Paul

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 1:06 pm

Hi Paul,

First the good news, when you turned on the clock and the servo responded, it shows that it is getting pulses.

I'm not a Python expert, but you do need to send the servo number and the required position in a single spi write operation. Otherwise, the input register resets between writes and the new position will not be latched.

Have a look at the example C program and see in 'exercise_pwms' how both the servo number and desired position are set into successive bytes in a char array. One way to do it would be to use the Python struct library and call the function pack() in order to do what you want. But there are likely simpler ways.

You'll learn a lot by trying to port the example code yourself, but please don't get stuck. Let me know if you are having problems getting it to work and I'll fire up Python and get something working for you.

HTH,

Derek
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 1:17 pm

Forgot the second question.

To write to the outputs, you simply pass 4 in the first byte, 0 to 3 being the 4 servos. The second byte then becomes the bit pattern for the outputs instead of a desired servo position. Output 0 is in the lowest numbered bit, I believe, so 0x01 will do the trick.

You might see an LED light dimly and get brighter as the servo turns more clockwise since the pulse is getting longer, and you might see some flickering. Don't forget to put a small resistor in series with the LED to limit the current. Not too big or it will be too dim to see.

However, you won't see the value change until you get the two bytes written in one SPI write and by that time, your servo will likely already be responding.

D.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

ptrav1956
Posts: 7
Joined: Thu Jul 31, 2014 9:31 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 1:32 pm

Derek,

thanks for the speedy reply. I had tried sending the two values as a python list but got an error that spi_write was expecting an integer value (I think that was what it was, not at my Pi at the moment) ie

Code: Select all

payload[0]=0
payload[1]=100
GZ.spi_write(payload)
gives an error. I will look into struct and pack .. at a quick glance it looks like i should have something like
payload = struct.Struct('B B') # unsigned char format lets me assign values between 0 - 255
values = payload.pack(0,100) # and has a byte length of 2
GZ.spi_write(values)
does that look reasonable? I'll give it a whirl when I get home.

Thanks again!

Paul

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 1:58 pm

GZ.spi_write(values)
Possibly GZ.spi_write(values.unpack(">I")) ?

Looking at the struct library docs, probably not, but you still need to get python to treat it as an unsigned int. There will be a way. :)

D.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

ptrav1956
Posts: 7
Joined: Thu Jul 31, 2014 9:31 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 3:18 pm

Derek,

yeah that seems to be the problem. I couldn't wait so SSH'ed in from work to check that code and, alas, it falls down on mot being an integer.
>>> import GZ
>>> import struct
>>> GZ.clock_ena(0,50)
>>> GZ.spi_set_width(2)
>>> payload = struct.Struct('B B')
>>> values=payload.pack(0,150)
>>> GZ.spi_write(values)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: an integer is required
if I look at the values to see what they are -
>>> values
'\x00\x96'
>>> payload.unpack(values)
(0, 150)
So it looks like pack is doing the right thing and generating two bytes to select the servo and the setting, but spi_write seems to want it as an integer. Or at least wants something as an integer.

I tried the same thing with bytearray, which looks to be the closest match to the way you have encoded things in c ... and got the same error
>>> test=bytearray(2)
>>> test[0]=0
>>> test[1]=100
>>> GZ.spi_write(test)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: an integer is required
I think I can access the other servos if I bit shift, eg to access servo 3
>>> v2=((2<<8)|100)
>>> v2
612
>>> bin(v2)
'0b1001100100'
>>> type(v2)
<type 'int'>
this does work in that spi_write is quite happy. But I can't figure out how to shift a 0 and not have it just be truncated.

But you are right, there must be a way!

Paul

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 3:49 pm

Try packing 4 bytes, with zero in the upper two.

now unpack with format 'i' and try passing that. If that doesn't work for you, I'll fire up Python myself and take a look.

Pythons variables are all implemented in C under the hood, so something is bound to work.

best,

Derek
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Thu Jul 31, 2014 5:50 pm

I had success with this function definition:

Code: Select all

def control_servo(servo_num, posn):
  value = struct.pack('BBBB', servo_num, posn, 0, 0)
  [tmp] = struct.unpack('i', value)
  GZ.spi_write(tmp)
There's probably a neater solution though.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

ptrav1956
Posts: 7
Joined: Thu Jul 31, 2014 9:31 am

Re: Guzunty Pi. New users start here.

Fri Aug 01, 2014 9:38 am

Ok we are getting somewhere .. that didn't work for me, so I will reload the test core and try the tests again, see if I can work out where things are going wrong. What I think I will do then is load the 1608i core and run the python program you have in the git repo and use that to try to work out what's happening before going back to the servo core.

Thanks for your help!

Paul

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Fri Aug 01, 2014 9:57 am

Hmmm, that is strange.

You got the servo to twitch and then the above code didn't work.

Probably a silly question, but you did remember to start the clock before calling the function?

My test code looks like this:

Code: Select all

def main():
  GZ.spi_set_width(2)
  GZ.clock_ena(0, 80)
  while True:
    for i in range(16):
      control_servo(0, 64 + (i * 8))
      time.sleep(0.1)
HTH
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Fri Aug 01, 2014 10:01 am

BTW, a general comment; I don't recommend running servos directly from the 5v pin on the Guzunty. The motors generate a lot of noise and while I haven't seen the Pi itself reboot, it upsets USB peripherals that take their power from the Pi.

Not saying you're doing that, Paul, just a tip for everyone reading.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

ptrav1956
Posts: 7
Joined: Thu Jul 31, 2014 9:31 am

Re: Guzunty Pi. New users start here.

Fri Aug 01, 2014 10:55 am

yeah I did remember to enable the clock :) Though I was using a divisor of 50, and I see yours is 80 - would that make a difference?

P.

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Fri Aug 01, 2014 11:31 am

It doesn't make any difference on the servo I'm using to test here, but servos do differ quite widely in what they will accept.

The value of 50/80 is a divisor for the PI's hardware clock. It controls both the rate at which pulses are sent to the servo and the width of the pulse for a given value.

The 80 value gives a pulse frequency of 112Hz and being a divisor, the lower value of 50 yields a higher frequency of 188Hz. They are both within spec but 188Hz is getting close to the upper limit of about 200Hz.

You could try using divisor values all the way up to about 200 (gives about 50Hz) and still be within spec.

Try some other values and let me know how that works for you.

HTH
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

guzunty
Posts: 276
Joined: Mon Jan 14, 2013 10:13 am

Re: Guzunty Pi. New users start here.

Fri Aug 01, 2014 11:35 am

My test servo is a Cirrus CS-60 BTW.

I also tested with a Hi-TecHS-325HB.

Both are OK at divisor values of 50, 80 and 100.
Guzunty: A fully programmable peripheral you build yourself! https://github.com/Guzunty/Pi/wiki

Return to “Other projects”