16 |
17 | #
18 |
19 | ## Install required libraries
20 |
21 | Connect your Pico to the computer and run Thonny. Select your Pico by clicking on the bottom right corner in Thonny. You should see the list of files on the Pico in the bottom left section. Stop any running process by clicking the Stop icon.
22 |
23 | In Thonny, go to Tools -> Manage Packages...
24 |
25 | Search for `microdot_asyncio` and install that. This will copy some files into the lib/ folder on your pico. It is needed for the web server that we use (same as cosmic_paint). Also search for and install `micropython-phew`.
26 |
27 | ## Setup WIFI_CONFIG.py and copy network_manager.py
28 |
29 | This script uses and requires the same `WIFI_CONFIG.py` that many of the other WiFi examples use (like cosmic_paint). That will need to be setup like this:
30 | ```
31 | SSID="fill this in with network name"
32 | PSK="fill this in with password"
33 | COUNTRY="GB or US or your country"
34 | ```
35 |
36 | You will also need to upload `network_manager.py` from the common folder
37 | - [micropython/examples/common](https://github.com/pimoroni/pimoroni-pico/blob/main/micropython/examples/common)
38 |
39 | https://github.com/pimoroni/pimoroni-pico/tree/main/micropython/examples/cosmic_unicorn#wireless-examples
40 |
41 | ## Installing on multiple Cosmic Unicorns
42 |
43 | A note that if you are installing this on multiple Cosmic Unicorns, that you can install the user interface code (which is quite large) on only one device. On the other devices you only need to install the server code `cosmic-emoji.py`
44 |
45 | ## Installing the server code without user interface
46 |
47 | - From the repo, install `cosmic-emoji.py` on your Pico.
48 | - Optionally copy `cosmic-emoji.py` to `main.py` if you want it to start on boot
49 | - In Thonny, run the file on the Pico, and get the IP address from the console
50 | - If it does not run, or you do not see the IP address, then setup `WIFI_CONFIG.py` or install required libraries and try again.
51 |
52 | If you go this route, then you will need to run the user interface on your computer or somewhere else. You will need the IP address above for configuration in the user interface.
53 |
54 | If you want to install both the server code and user interface on the Pico, read on..
55 |
56 | ## Installing the server code and user interface
57 |
58 | Here are the instructions for running the server code and user interface on the Pico, using the latest pre-built release:
59 |
60 | - Download the latest from the GitHub releases. [https://github.com/chriscareycode/cosmic-unicorn/releases](https://github.com/chriscareycode/cosmic-unicorn/releases) . You only need the cosmic-emoji-react-v0.0.4.zip file, not the source code files.
61 |
62 | - Extract the file.
63 |
64 | - Copy `cosmic-emoji/config-unicorns.example.json` to `cosmic-emoji/config-unicorns.json`
65 |
66 | - Edit the file `cosmic-emoji/config-unicorns.json` with your Unicorn IP address.
67 |
68 | - If you have multiple Cosmic Unicorns, you can add multiple entries to control them all. Make sure to add commas in the right spots so the file is valid JSON format. You may want to install the user interface only on one of the Picos, and install server files only on the others. It's up to you.
69 |
70 | ### Edit the config file with your Pico IP address
71 |
72 | If you know the IP address that your pico has, then edit that IP address in the `config-unicorns.json` file.
73 |
74 | If you do not know the IP address, then upload `cosmic-emoji.py` and run that. In the Thonny console it will tell your the IP address if WiFi connection is successful. Edit the `config-unicorns.json` with the IP address of your pico and save the config file.
75 |
76 | ### Upload the files (with user interface)
77 |
78 | Upload the rest of the files to the pico using Thonny or another tool.
79 |
80 | Copy the files to your pico:
81 | - cosmic-emoji.py
82 | - cosmic-emoji/index.html
83 | - cosmic-emoji/config-unicorns.json
84 | - cosmic-emoji/static/ (folder with css and js files)
85 |
86 | `cosmic-emoji.py` is the server and goes in the root of your pico, and the `cosmic-emoji/` folder contains the user interface.
87 |
88 | ### Optionally make this script run when the Pico boots up
89 |
90 | If you want this script to run on boot, then you need to copy the contents of `cosmic-emoji.py` into `main.py`. main.py is the file that starts on boot.
91 |
92 |
93 |
94 |
95 | You're all set. Start the program and look for the IP address to connect to.
96 |
97 | #
98 | # Running the user interface in Development mode
99 |
100 |
101 | ### Running in local development
102 |
103 | This project started as a standard React app created with create-react-app. Then TypeScript was added. Then switched to Preact (to reduce the bundle size). The bundle is still quite large (in pico terms) at like 290KB.
104 |
105 | Git Clone this project
106 |
107 | - `git clone https://github.com/chriscareycode/cosmic-unicorn.git`
108 |
109 | Change into cosmic-emoji-react folder
110 |
111 | - `cd cosmic-emoji-react`
112 |
113 | Setup the config-unicorns.json file:
114 |
115 | - Copy `public/config-unicorns.example.json` to `public/config-unicorns.json`
116 |
117 | - Edit the file `public/config-unicorns.json` with your Unicorn IP address.
118 |
119 | You need Node.js/npm installed to do development on this project.
120 |
121 | ### `npm install`
122 | ### `npm start`
123 |
124 | Then connect to the local IP address and do your local development! Open [http://localhost:3069](http://localhost:3069) to view it in the browser.
125 |
126 | ### Building the project for use on the Pico
127 |
128 | When you are done editing files, create a build with this command:
129 |
130 | ### `npm run build`
131 |
132 | Then run this special delete command to delete the extra files in the build folder to free up needed space (since the pico has such little space):
133 |
134 | ### `./delete-extra-build-files.sh`
135 |
136 | The built files will be in the pico/ folder.
137 |
138 | Upload the files to your pico with Thonny.
139 |
140 | #
141 |
142 | Thanks to Pimoroni for creating these awesome boards!
143 |
144 | 2023 Chris Carey
--------------------------------------------------------------------------------
/cosmic-paste/cosmic-paste.html:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
13 |