Xojo Python

broken image


From Xojo Documentation

I've been writing Python for a number of years now and have become a great fan of PyCharm from JetBrains. They have a free community edition to get started and the 'Professional' version really makes some of the more complex application developmen. Xojo is a cross-platform development tool and object-oriented programming language for creating powerful, native applications for macOS, Windows, Linux, the web, iOS, and Raspberry Pi. Python bindings for RRDtool for Python 2 and 3. The bindings are based on the code of the original Python 2 bindings module for rrdtool by Hye-Shik Chang and are now shipped with the RRDtool distribution. This project is maintained separately to provide a more pythonic way to install those bindings via PyPI. With Xojo, you can create desktop and console apps for your Raspberry Pi all from a slick integrated development environment using drag and drop, along with the simple and straight-forward Xojo programming language. Plus, Xojo is cross-platform and multi-platform, so your apps can also easily work on Windows, macOS, Linux and the web. It is a GUI application written in Xojo with some additions in python.


New in 2010r4

This is the base class for the Session class that is included in all web projects. Each user session gets its own instance of WebSession that you can access using the Session method.

Xojo Python Plugin

To refer to the current Session from within the Session object, use Self instead of Session as the prefix, especially in the Opening event because it may return Nil.
Events
ActivatedHashTagChangedScaleFactorChanged
AllowUnsupportedBrowserJavaScriptErrorUnhandledException
AppearanceChangedOpeningUserDisconnected
ClosingOrientationChangedUserTimedOut
DataReceivedPreparingSession
DeactivatedRequestedData
Properties
AllowTabOrderWrapDisconnectMessageLanguageRightToLeft
HashTag
ConfirmDisconnectMessageInterruptionMessage
UserTimeout
CurrentPageLanguageCode


Methods
ExecuteJavaScriptPageCountSaveState
GotoURLPageWithNameSecure
HasPagePagesURLParameter
HasPageNamedQuitURLParameterCount
HeaderRawHeadersURLParameterExists
HeaderAtRecordDataURLParameterName
HeaderCountRemoveData
PageAtRequestData

Notes

Use the Session object to access the current user session.

To refer to the current Session from within the Session object, use Self instead of Session as the prefix, especially in the Opening event because it may return Nil.

Databases

If your application is going to connect to a database server, you will want to store the database connection in a property of the Session class. This will allow your application to make connections to the server on a user-by-user basis.

Query Parameters

To access the query parameters, use the URLParameter methods to retrieve the query parameters from the Session object.

See Also

Session, WebSessionContext classes.

Retrieved from 'http://docs.xojo.com/index.php?title=WebSession&oldid=77686'

From Xojo Documentation

In this tutorial, you will create a simple circuit with an LED and will then make the LED blink using a simple Xojo app.

Parts

In order to build the circuit, you'll need some parts:

Xojo Python
  • 1 ribbon cable with Raspberry Pi GPIO connectors (AdaFruit link)
  • 1 cobbler (AdaFruit link)
  • 1 breadboard (AdaFruit link)
  • 3 jumper wires (AdaFruit link)
  • 1 LED (AdaFruit link)
  • 1 10k resistor (SparkFun link)

In order to make the LED blink with Xojo, you'll need to install the wiringPi library and grab the WiringPiXojo module, located here:

Examples/Platform-Specific/Linux/Raspberry Pi

Or you can download the latest version from GitHub.

Connect Ribon Cable to Pi

Connect the ribbon cable to the Raspberry Pi. The white/black side is typically facing the side of the Pi that does not have connectors. There is not a lot of room to work so take your time and make sure the pins are all aligned before you push it down.

Pi Ribbon Cable

Setup the Breadboard

A breadboard is the place where you will wire your circuit. The ribbon cable and cobbler are essentially used to extend the GPIO port pins to the breadboard. On the breadboard you can wire everything without soldering. You just plug things into the holes on the breadboard.

First, you'll want to plug your cobbler into the breadboard. The cobbler has to be in the center so that the left and right pins are separated by the center channel of the breadboard. In this picture, a 't-cobbler' is used and it is plugged near the top of the board to maximize available space on the board for wiring.

Cobbler on Breadboard

Carefully make sure all the pins are lined up with the holes on the breadboard and push it down. It may take a bit of force, but you want to get the cobbler to be flush with the breadboard.

The last step is to connect the cobbler to the Raspberry Pi. Plug the other end of the ribbon cable into the cobbler. It's likely the cobbler will have a slot in it so that the ribbon cable only fits in one direction.

With the breadboard connected, you now have access to the pins on the GPIO port. As you can see in the photo above, this cobbler has each of the pins labelled so you can easily tell what they are for without having to count them.

Each row on the breadboard that matches up to a pin on the cobbler is 'connected' to the pin on the cobbler. Any wires you connect on that row will act as if they are connected to pin on the GPIO port. For example, looking at the cobbler, you can see that the pin marked '#17' is aligned with row 6 on the cobbler.

Wire the Circuit

Now that you have the breadboard hooked up to the Raspberry Pi, you can start on building the blinking LED circuit. In this step you'll use 3 wires, 1 LED and a resistor.

  1. Connect a wire to the pin marked '#4'. Yellow is used in this example.
    LED Blinker Step 1
  2. Connect the other end of the wire to an open spot on the board away from the cobbler. Here row 24 is used.
    LED Blinker Step 2
  3. Grab the LED. Note that one of the wires coming from the LED is longer than the other. The longer end is the positive (+) connector. Plug the long end into a hole on the breadboard adjacent to the wire (yellow) and the short end to an open row on the breadboard.
    LED Blinker Step 3
  4. A resistor is needed to prevent the power provided by the Pi from blowing out the LED. Take the 10k resistor and connect one end so that it is adjacent to the negative wire of the LED. Connect the other end of the resistor to an open spot on the board. If you cross over the center of the board to the other side, you can take advantage of the same row, which is what is done here.
    LED Blinker Step 4
  5. Now connect another wire adjacent to the unconnected resistor wire. Connect this wire to the negative (-) column on the breadboard. This is usually the column on the outer edge.
    LED Blinker Step 5
  6. Lastly, connect a wire from the negative column of the breadboard to a GND pin on GPIO. There are several GND pins; you can use any one that is easily reachable.
    LED Blinker Step 6
  7. This completes the circuit.


You can quickly test the circuit by moving the yellow wire from pin #4 to pin 3v3. This directly connects the circuit to 3.3 volt power. The LED should immediately light up. Switch it back to the #4 pin before moving on to creating the Xojo app.

Xojo Python

Create the Xojo app

To test your circuit, you'll use a simple Xojo app that will alternate between ON (HIGH) and OFF (LOW) on pin #4. When the pin is ON (HIGH), the LED will illuminate.

  1. Create a new Console project and call it LEDBlinker.
  2. Add the GPIO module to the project.
  3. Add this code to the App Run event handler:
GPIO.SetupGPIO
Const kLEDPin = 4' '#4' on the pinout
' Set the pin to accept output
GPIO.PinMode(kLEDPin, GPIO.OUTPUT)
' Blink LED every 1/2 second
WhileTrue
' Turn the pin on (give it power)
GPIO.DigitalWrite(kLEDPin, GPIO.ON)
App.DoEvents(500)
' Turn the pin off (no power)
GPIO.DigitalWrite(kLEDPin, GPIO.OFF)
App.DoEvents(500)
Wend

Make sure you've selected Linux in Build Settings and its architecture to ARM 32-bit in the Inspector and then Build the app.

Transfer and Run the Xojo app

Start your SFTP app and connect to the Raspberry Pi. Transfer the LEDBlinker folder from the Linux build folder to the Pi.On the Pi, open the Terminal (or ssh to it from your development machine). In the terminal, navigate to the location of the LEDBlinker folder and then CD to the folder:

Run the app:

Normally sudo is needed to access GPIO. The GPIO.SetupGPIOSys method does provide access to some GPIO functionality without requiring sudo.

The LED should start blinking. To stop the app, press Control-C.

Note that if you press Control-C while the LED is on, it will remain on.

Starting with Raspbian Jessie, you no longer have to use sudo to access GPIO. In order to not require sudo, you have to first set an environment variable before you run the app:

The Xojo project is included with the Xojo examples and is located here:

Examples/Platform-Specific/Linux/RaspberryPi

Video

Watch the companion step-by-step video.

Circuit Diagram

Xojo python plugin
  • 1 ribbon cable with Raspberry Pi GPIO connectors (AdaFruit link)
  • 1 cobbler (AdaFruit link)
  • 1 breadboard (AdaFruit link)
  • 3 jumper wires (AdaFruit link)
  • 1 LED (AdaFruit link)
  • 1 10k resistor (SparkFun link)

In order to make the LED blink with Xojo, you'll need to install the wiringPi library and grab the WiringPiXojo module, located here:

Examples/Platform-Specific/Linux/Raspberry Pi

Or you can download the latest version from GitHub.

Connect Ribon Cable to Pi

Connect the ribbon cable to the Raspberry Pi. The white/black side is typically facing the side of the Pi that does not have connectors. There is not a lot of room to work so take your time and make sure the pins are all aligned before you push it down.

Pi Ribbon Cable

Setup the Breadboard

A breadboard is the place where you will wire your circuit. The ribbon cable and cobbler are essentially used to extend the GPIO port pins to the breadboard. On the breadboard you can wire everything without soldering. You just plug things into the holes on the breadboard.

First, you'll want to plug your cobbler into the breadboard. The cobbler has to be in the center so that the left and right pins are separated by the center channel of the breadboard. In this picture, a 't-cobbler' is used and it is plugged near the top of the board to maximize available space on the board for wiring.

Cobbler on Breadboard

Carefully make sure all the pins are lined up with the holes on the breadboard and push it down. It may take a bit of force, but you want to get the cobbler to be flush with the breadboard.

The last step is to connect the cobbler to the Raspberry Pi. Plug the other end of the ribbon cable into the cobbler. It's likely the cobbler will have a slot in it so that the ribbon cable only fits in one direction.

With the breadboard connected, you now have access to the pins on the GPIO port. As you can see in the photo above, this cobbler has each of the pins labelled so you can easily tell what they are for without having to count them.

Each row on the breadboard that matches up to a pin on the cobbler is 'connected' to the pin on the cobbler. Any wires you connect on that row will act as if they are connected to pin on the GPIO port. For example, looking at the cobbler, you can see that the pin marked '#17' is aligned with row 6 on the cobbler.

Wire the Circuit

Now that you have the breadboard hooked up to the Raspberry Pi, you can start on building the blinking LED circuit. In this step you'll use 3 wires, 1 LED and a resistor.

  1. Connect a wire to the pin marked '#4'. Yellow is used in this example.
    LED Blinker Step 1
  2. Connect the other end of the wire to an open spot on the board away from the cobbler. Here row 24 is used.
    LED Blinker Step 2
  3. Grab the LED. Note that one of the wires coming from the LED is longer than the other. The longer end is the positive (+) connector. Plug the long end into a hole on the breadboard adjacent to the wire (yellow) and the short end to an open row on the breadboard.
    LED Blinker Step 3
  4. A resistor is needed to prevent the power provided by the Pi from blowing out the LED. Take the 10k resistor and connect one end so that it is adjacent to the negative wire of the LED. Connect the other end of the resistor to an open spot on the board. If you cross over the center of the board to the other side, you can take advantage of the same row, which is what is done here.
    LED Blinker Step 4
  5. Now connect another wire adjacent to the unconnected resistor wire. Connect this wire to the negative (-) column on the breadboard. This is usually the column on the outer edge.
    LED Blinker Step 5
  6. Lastly, connect a wire from the negative column of the breadboard to a GND pin on GPIO. There are several GND pins; you can use any one that is easily reachable.
    LED Blinker Step 6
  7. This completes the circuit.


You can quickly test the circuit by moving the yellow wire from pin #4 to pin 3v3. This directly connects the circuit to 3.3 volt power. The LED should immediately light up. Switch it back to the #4 pin before moving on to creating the Xojo app.

Xojo Python

Create the Xojo app

To test your circuit, you'll use a simple Xojo app that will alternate between ON (HIGH) and OFF (LOW) on pin #4. When the pin is ON (HIGH), the LED will illuminate.

  1. Create a new Console project and call it LEDBlinker.
  2. Add the GPIO module to the project.
  3. Add this code to the App Run event handler:
GPIO.SetupGPIO
Const kLEDPin = 4' '#4' on the pinout
' Set the pin to accept output
GPIO.PinMode(kLEDPin, GPIO.OUTPUT)
' Blink LED every 1/2 second
WhileTrue
' Turn the pin on (give it power)
GPIO.DigitalWrite(kLEDPin, GPIO.ON)
App.DoEvents(500)
' Turn the pin off (no power)
GPIO.DigitalWrite(kLEDPin, GPIO.OFF)
App.DoEvents(500)
Wend

Make sure you've selected Linux in Build Settings and its architecture to ARM 32-bit in the Inspector and then Build the app.

Transfer and Run the Xojo app

Start your SFTP app and connect to the Raspberry Pi. Transfer the LEDBlinker folder from the Linux build folder to the Pi.On the Pi, open the Terminal (or ssh to it from your development machine). In the terminal, navigate to the location of the LEDBlinker folder and then CD to the folder:

Run the app:

Normally sudo is needed to access GPIO. The GPIO.SetupGPIOSys method does provide access to some GPIO functionality without requiring sudo.

The LED should start blinking. To stop the app, press Control-C.

Note that if you press Control-C while the LED is on, it will remain on.

Starting with Raspbian Jessie, you no longer have to use sudo to access GPIO. In order to not require sudo, you have to first set an environment variable before you run the app:

The Xojo project is included with the Xojo examples and is located here:

Examples/Platform-Specific/Linux/RaspberryPi

Video

Watch the companion step-by-step video.

Circuit Diagram

Here is a circuit diagram for reference:

LED Blinker Circuit
Retrieved from 'http://docs.xojo.com/index.php?title=GettingStarted:Raspberry_Pi_Blinking_LED_Tutorial&oldid=76523'




broken image