InVyu, pronounced "in view," is exactly what it sounds like. This is the maker and hacker’s wearable heads-up display (HUD), letting you put what’s important in view. Some cool things that InVyu can be used for are:
- Sports coach assistant (Timers, notes)
- Presentation notes viewer
- Instant weather reporting
- On-the-road directions (biking, walking, running)
- Time zone tracker
- IFTTT triggers
HUDs work by projecting images or text onto a transparent or translucent surface. This gives the illusion of images or text floating in the space of where you look. InVyu accomplishes this illusion by using OLEDs, bi-convex lenses, and a transparent piece of plastic.
The key to this illusion is the translucent plastic. The translucence of the plastic allows you to view the light emitting from the OLED while continuing to see the outside world. The lenses help focus that light, so what you see from the OLED is just as sharp as the rest of your world. The lens’s job in an HUD is very similar to what they do in VR headsets. You can also try this with your phone and a magnifying glass: turn on your phone and hold the display right in front of your eyes. Can you read the text or see the images clearly? Now try this again, but this time put a magnifying glass (which is a bi-convex lens) in between your phone and your eyes. Isn't it much clearer?
InVyu is not a standalone device. Through a BLE connection with your phone, InVyu can interact and collect new data to be displayed! In this tutorial, I will show you how to:
- Build your own InVyu
- How to program it
- How to build your own firmware
- How to interact with it through iOS
- How to build your own iOS app for interfacing
Head back up to the "Things" section and gather the materials. Read the comments too, they are important! Once you have acquired the materials, head over to the “Custom parts and enclosures” section, download the DXF file for InVyu’s case, and laser cut it. Because each laser cutter may have a different setup process, this tutorial won’t go through how to laser cut. As the comment suggests: please use 1/8in (3.175mm) wood!!! This case was designed for this thickness of wood and certain parts may not fit the same if a thinner or thicker wood is used. If you see a change you would like to make to the case, feel free to download the f3d file and edit the case in Fusion 360. Now that you have gathered all of the required material, it’s time to start building!
Hardware: Assembling the CaseIn this section we will assemble InVyu’s case and install the optics. Because the case encapsulates the OLED and lenses, make sure you have those with you before you start this section. When assembling, refer to the following image for part identification/label:
1. Gather the pieces from your laser cutter and arrange them as they were cut.
2. Take the F pieces, split them up, and rearranged them as shown in the following image. These pieces are used for holding the lenses.
3. Insert them into the given slots on pieces A and C as shown in the following image. Use wood glue to adhere the F pieces to A and C.
4. Repeat step 3 with all eight F pieces.
5. Fold piece B towards piece C making sure they fit together like a jigsaw puzzle. Glue these two pieces together.
6. Take pieces H and E and place them along B and C as shown in the following images. Glue H and E to their spots alongside B and C.
7. Flip pieces I, J, K, L, and M around as shown in the following image. This will help set up the next few steps.
8. Fold J towards I and glue the two pieces together at their connection point.
9. Take L and insert it into the slot provided on I as shown. Glue the piece down.
10. Take M and insert it into the slot provided on I as shown. Glue the piece down.
11. Complete the structure on I by taking K and placing it on top of J, L, and M as shown. Glue the piece down.
12. Take G and place it in the slot provided on I as shown.
13. Take your OLED displays and insert them in the slots between B and C as shown in the following image. Part of the OLED slides into the slits on C and the pins of the OLEDs are in the slits on B.
14. Take your lenses and orient them so the larger “bulb” of the lens faces upward. Use the following image to understand the correct orientation.
15. Place the lenses in the rack created by the F pieces with the larger “bulb” facing away from the OLEDs.
Don't stress about it if you are having a hard time identifying the larger "bulb" of the lens, I just found through my testing that this orientation works slightly better.
16. Take A and place it on top of the structure created by B, C, E, and H. Do not glue this piece down yet, we adhere the pieces later. Make sure the OLEDs are held between the slits in A and C. Also, make sure the lenses are held between the F pieces.
At this point your assembly should look like this:
17. As you may have noticed, piece A does not sit perfectly flush on top of B, E, and H. This is because the F pieces pushes against the lens, causing it to not sit flush on A and C. This is not a flaw; this flexibility allows you to adjust the clamp pressure on the lenses to prevent them from shattering. Use tape or glue to adhere A to the rest of the structure.
18. Flip the OLED/lens enclosure so C is above A as shown in the following image. Arrange D as shown in the following image.
19. Fold the OLED/lens enclosure structure towards D. Glue the pieces together.
20. Take the structure formed from pieces I, J, K, L, and M and attach it to the other side of the OLED/lens enclosure, adjacent to D.
21. Finally, find a piece of clear plastic and cut it so one end can be adhered to the far side of the OLED enclosure and the other end can be adhered to the bottom of the nose bridge. Make sure it spans the width of one eye piece. Cut out two of these (one for each eye piece). These are the translucent pieces of plastic that acts as the “display” part of a HUD.
Now that you have assembled the case, lets add the electronics!
Hardware: ElectronicsGather the rest of the materials from the “Things” section and also grab a soldering kit (iron, solder, and wires). Electrical tape is optional but can be helpful to help insulate exposed wires. First, we will attach the rest of the components to the case, then we will wire them all to the MAX32620FTHR.
1. Take the HM-10 BLE module and slide it into the case created by pieces I, J, K, L, and M.
2. Take the Mx2125 accelerometer and slide its pins into the slots in G. The direction indicator on the Mx2125 should be pointing towards the OLEDs and lens enclosure.
I should look like this:
3. Take the MAX32620FTHR and align it so that its holes are lined up with the holes on D and the Micro-USB port is facing away from the OLED enclosure. Use a small piece of tape to attach the MAX32620FTHR to D. You will have to remove the board later for soldering, so you may not want to permanently attach the board at the moment. Later, you can attach the MAX32620FTHR in any way you like.
Now on to wiring! Go to the “Schematics” section to reference the circuit wiring diagram.
4. Attach female/female jumper wires to the pins of the Mx2125, HM-10, and OLEDs as shown in the circuit wiring diagram. In total that should be 17 female/female wires.
5. With your spool of wire (labeled male/male jumper wires in the “Things” section) and some solder, create the wire joint shown in the following diagram. The “Y” posts of the joint should be the depth of a female/female wire port and the single wire after the two pieces merge should be long enough for another wire to be soldered on.
6. Repeat step 5 four more times so you have fives wire joints in total.
7. Take one of your wire joints and join the female/female wires connected to theMx2125 GND pin.
8. Take your spool of wire and cut a piece of wire that can connect from the female/female wire on the VCC pin of the HM-10 to the 3.3V pin on the MAX32620FTHR (shown in the circuit wiring diagram).
9. Repeat step 5 for the remaining pins on the HM-10 and the Mx2125 to their corresponding pins on the MAX32620FTHR (use the circuit diagram as pin reference). Pretend the wire joint you made in step 7 is also a female/female wire.
10. Solder the wires you cut in steps 8 and 9 into the MAX32520FTHR and attach them to the jumpers on the components. Obviously use solder for the wire joint you connected in step 7.
11. Use the remaining wire joints to join the corresponding pins on the OLEDs together(VCC to VCC, GND to GND, …).
12. Repeat step 8 for the wire joints used in the previous step.
13. Solder the wires you cut in the previous step to the wire joints. Connect them to the ports on the MAX32620FTHR as shown in the circuit diagram
That’s it! You have successfully built your own InVyu. Now, let’s go program it and bring your InVyu to life!
InVyu Firmware: Installing the Demo FirmwareBefore we begin, please know that the following few sections is written in a “cookbook” style. This means I won’t really do much explanation on the code and why we do certain things. There will be sections afterwards that will go in depth to explain the code and how you, a maker or hacker, can go about programing your own firmware/software for your InVyu.
Uploading firmware to the MAX32620FTHR couldn’t be easier. When plugged in, the board will appear as a removable drive like a USB flash drive.Simply drag and drop your compiled binary (.bin) file into the drive and you’ve uploaded the firmware! Before we jump into getting the firmware, let’s make sure you can successfully connect your InVyu to your computer.
1. Find the programming cable and the tiny MAX32625PICO that came with yourMAX32620FTHR
2. Connect one end of the programming cable to the MAX32620FTHR and the other to theMAX32625PICO. There are connection guides, so you don’t have to worry about orientation.
3. Grab your Micro-USB to USB cables (as listed in the “Things” section).
4. With a USB cable you just grabbed, connect the Micro-USB port of the MAX32620FTHR to a 5v power source (such as one of your computer’s USB ports).
5. With the other USB cable, connect the Micro-USB port of the MAX32625PICO to a USB port on your computer.
6. After some flashing lights, a drive named “DAPLINK” should appear. This is the drive you will upload your binaries to.
Wasn’t that easy?
To get the demo firmware for InVyu, you have two options: 1) download the pre-compiled binary and upload it, or 2) download the source code and compile/build the firmware yourself. Option 1 is really simple:
7. Head over to the “Code” section.
8. Click on the “InVyu_Firmware.bin” tab.
9. Download the file.
10. Navigate to where you downloaded the binary file. Drag and drop the downloaded file to the DAPLINK drive.
11. Wait for the flashing lights to stop and look to see that the DAPLINK drive has reconnected.
12. If your MAX32620FTHR hasn’t done so, press the reset button to start the program.
That’s it!
Option 2 has some more steps but is also straightforward.(Note: I will be showing option 2 with the online compiler. If you prefer to use the CLI… well, you probably know what you’re doing and can easily following along using the CLI commands)
7. Head over to the “Code” section.
8. By default, the “main.cpp” tab should be selected, switch to that tab if it isn’t.
9. Download the file or keep it there as we will come back to it later.
10. Go to https://os.mbed.com/
11. Click on the yellow “Compiler” button in the top right corner
12. If you’re signed in already, this will bring you to the compiler. If not, sign in or create a new Arm Mbed account.
13. Once in the compiler, click on the platform button in the top right corner. This button may show different things. If you are a returning user, this button will show the last platform you compiled for.
14. Click the “Add Board” button.
15. You should spend all day scrolling through Arm Mbed’s catalog of boards to find theMAX32620FTHR, or you could narrow down your search with the Maxim Integrated filter.
16. Once you find the MAX32620FTHR, select it.
17. In the subsequent page, click on the “Open Mbed Compiler” button.
18. This button will automatically open the online compiler with the MAX32620FTHR as the selected board. In the dialog the appears, change the “Program Name:” to whatever you want (such as “InVyu” or “Firmware”). Don’t worry about the “Template:”section since we will be pasting in our own code. Click OK once you’re ready
19. Now that the program is created, let’s install libraries! Click on the “Import”button in the top left corner to begin.
20. Click on the search box, type in “Adafruit_GFX” and press search. Select the libary by Neal Horman and finally press “Import!”.
21. In the following dialog box, make sure the “Target Path:” points to your newly created program and that the “Update:” option is ticked.
22. Repeat steps 19-21 for the libraries “Pulse” by Nick Ryder and “MAX17055” by Team Maxim Integrated. You may have to use the page scroll option at the bottom to find the latter as it isn’t as popular as the other libraries.
Now that you have imported all of the libraries, let’s configure the SSD1306 driver library for the InVyu!
23. Double click the “Adafruit_GFX_Config.h” file to open it. Uncomment lines 5 and lines 8. Save the file and close.
24. Double click the “Adafruit_SSD1306.cpp” file to open it. Go to line 44 and change the defined value from 0xC8
to 0xC0
. Go to line 45 and change the defined value from 0xA0
to 0xA1
. Lines 44 and 45 should now be
#define SSD1306_COMSCANDEC 0xC0
#define SSD1306_SEGREMAP 0xA1
Save and close the file.
25. Finally, double click the “Adafruit_SSD1306.h” file to open it. Go to line 53 and change the value of the parameter rawHeight
to 64
. Line 53 should now say
Adafruit_SSD1306(PinName RST, uint8_t rawHeight = 64, uint8_t rawWidth = 128)
26. Repeat step 25 with line 173. It should now say
Adafruit_SSD1306_I2c(I2C &i2c, PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 64, uint8_t rawWidth = 128)
Save and close the file
27. Head back to the “Code” section in Hackster or wherever you stored the demo firmware’s code. Copy the code.
28. Open main.cpp in the compiler. Remove all of the code and paste the code you just copied. Save the file.
29. Click on the “Compile” button.
30. When prompted, save the binary file.
31. Navigate to where you downloaded the binary file. Drag and drop the downloaded file to the DAPLINK drive.
32. Wait for the flashing lights to stop and look to see that the DAPLINK drive has reconnected.
33. If your MAX32620FTHR hasn’t restarted, press the reset button to start the program.
Pretty straightforward right? Just like that you have installed a demo firmware for your InVyu. Take the time now that something is being display to adjust the OLED displays and lenses so you can have a stereoscopic view. The enclosure lets the OLED and lenses to slide left and right, allowing you to adjust the view so data is displayed directly in your line of sight.
InVyu Software: Installing the iOS Demo SoftwareTo interact and gather more data, InVyu connects via BLE to your phone. To keep things simple, this tutorial focuses on using iOS 11/12 and Swift 4. To install the demo app on your phone, you will need a Mac with Xcode > 9. This application was developed with Xcode 10 beta 4 and iOS 12 beta 4.The codes will still work with Xcode 9 and iOS 11, but you may need to change the deployment setting (which I will go over). Here’s how to install the demo app:
1. Head over to the “Code” section, switch to the “InVyu Activities” tab, and download the.zip file
2. Unzip the folder, open it, and double click the “InVyu Activities.xcodeproj” to open it in Xcode. If a dialog pops up asking if you want to open this project (because it was downloaded from the internet and may contain threats), click “Open”and open the project.
3. When opened, you will land at the General settings/info of the Xcode project. Apply any signing data with your Apple ID if needed. Also, under the “Deployment Info” section of the General settings, change the “Deployment Target” to match your iPhone’s OS
4. Turn on, unlock, and plug in your phone to your Mac.
5. Open the build targets drop down menu.
6. Scroll up and select your phone.
7. If it has been a while (or if this is your first time) connecting to Xcode, your phone may need to be setup. Don’t worry, Xcode will do all of this for you, you just have to wait for it to finish.
8. Once Xcode has finished “preparing the debugger” simply press the play button in the top left corner to build and run the project.
9. If this is your first time installing an application from Xcode onto your phone, you may have to allow access to the profile. Simply follow the instructions Xcode gives you to allow access.
That’s it! You now have all of your demo apps installed. Here’s a video showcasing the Demo app running on an iPhone SE and an iPhone X simulator:
Here are some things you can do with your InVyu using the Demo Firmware and Demo app:
Setting the Time:
Get the weather by using the "looking upward" gesture:
Reading Custom Text set from the Activities app:
Triggering IFTTT events with set gesture (in this case, tilting left):
As you may have noticed, there are a few Activities in the Demo app that actually don’t do anything. The Stopwatch, Timer, and Check List were extra activities put in place for your own development. Rather than busying yourself with the UI details, you can jump right into developing.
InVyu Firmware: Programming TutorialNow that you’ve seen some of the things that InVyu can do, let’s go learn how to make them ourselves! (Note: prior knowledge/experience with programming and troubleshooting is assumed)
In your InVyu there are four major components
· 128x64 Monochrome OLED and Bi-convex lenses
· HM-10 BLE Module
· Mx2125 Accelerometer
· MAX32620FTHR (including the MAX17055 battery gauge)
The OLEDs and their lenses obviously are import for the visual aspect of a HUD as we have gone over in the introduction. The HM-10 BLE is important because that is how the InVyu communicates with your devices to collect new information. The Mx2125 is your way to interact with the InVyu, giving you a hands-free experience. And finally, the MAX32620FTHR and the onboard MAX17055 are there to help power and control it all. Let’s start with learning how to program your InVyu’s OLED!
1. Create a new program and import the Adafruit_GFX library by Neal Horman
2. Open “main.cpp” in your program and add the library with
#include “Adafruit_SSD1306.h”
Let’s do some configuration! Because the light projected from an OLED is reflected off a surface, we will get a mirrored image. For example, a projected “d” will look like a “b”. Because InVyu’s OLEDs are oriented upside-down, that “d” will look actually like a “P”. To fix this we change the value of two config variables:
3. Open “Adafruit_SSD1306.cpp” and navigate to lines 44 and 45. These lines are responsible for organizing the buffer for display. At the moment they should look likethis:
#define SSD1306_COMSCANDEC 0xC8
#define SSD1306_SEGREMAP 0xA0
Change 0xC8
to 0xC0
and 0xA0
to 0xA1
. This change will a) pre-mirror the output of the buffer so we can cancel out the projected mirror effect, and b) pre-flip the buffer upside-down so what we see is right side up. Lines 44 and 45 should now look like
#define SSD1306_COMSCANDEC 0xC0
#define SSD1306_SEGREMAP 0xA1
4. Save and close the file
The next thing we need to configure is the display size. The library defaults to displaying data for OLEDs with a 128x32 resolution, InVyu’s displays has a 128x64 resolution.
5. Open “Adafruit_SSD1306.h” and navigate to line 53. Change the value of the parameter rawHeight
to 64
. Line 53 should now say
Adafruit_SSD1306(PinName RST, uint8_trawHeight = 64, uint8_t rawWidth = 128)
6. Repeat step 4 with line 173. It should now say
Adafruit_SSD1306_I2c(I2C &i2c,PinName RST, uint8_t i2cAddress = SSD_I2C_ADDRESS, uint8_t rawHeight = 64, uint8_t rawWidth = 128)
Save and close the file
7. Finally, open “Adafruit_GFX_Config.h” and uncomment lines 5 and 8. The surrounding comments do a good job at explaining why.
By scanning through the file “Adafruit_GFX.h” you can actually learn every single possible command for the OLED. The file is heavily commented so you can understand how each and every command works.This library is a conversion of the original Adafruit library built for Arduino, so if you are familiar with that library then you know how to operate this one. Here are some simple/helpful commands to know:
- Initializing:
I2C i2c(P1_6, P1_7);
Adafruit_SSD1306_I2c oled(i2c, P2_7);
These two lines simply initialize the OLEDs as oled
from the I2C pins P1_6
and P1_
7 (which are the ones used in your InVyu).
- Printing to the buffer:
oled.printf(“Hello World”);
This command will add “Hello World” wherever the cursor is to the buffer.
- Moving the cursor:
oled.setTextCursor(0, 0);
This command will move the cursor to the given coordinates in pixels. For a 128x64 display, the x-axis ranges from 0-128 while the y-axis ranges from 0-64. Like most other coordinate planes, the origin (0, 0) is located in the top left corner of the display.
- Clearing the buffer:
oled.clearDisplay();
Erase the buffer.
- Displaying:
oled.display();
As you may have noticed, I have been using to word “buffer” rather than “display”. This is because the library has changes added to the buffer first (like printfs
or setTextCursors
)then displays the buffer when once all of the changes are made. Simply add oled.display();
after your commands to have the changes appear on your OLED.
Now that you know how the OLED works, let’s move to the next component: the HM-10. This one is really easy; no imports are required! BLE is treated as a Serial connection: initialize a serial port in a program and send away!
- Initialize a serial port:
Serial sr(P3_1, P3_0);
Initialize a serial port named sr
with the TX and RX pins
- Configure the baud rate:
sr.baud(9600);
Setting the baud rate to 9600
- Send a byte:
sr.putc(105);
This command sends a single byte (“i” for this example) into the serial port. The values are the ascii characters in decimal.
- Read a byte:
int in = sr.getc();
This is how you read a byte from the stream. in will return a decimal ascii code. To check the serial port for new data, use sr.readable()
. This will return true if there is something to read
That’s all you need to communicate via BLE! Initialize a Serial object and send away! You can read the full documentation here
The next component is the Mx2125 Accelerometer.
1. Create a new program and import the “Pulse” library by Nick Ryder
2. Open “main.cpp” in your program and import the program with
#include “Pulse.h”
No configuration is needed. You now have the Pulse library in your program and you can now gather data from the accelerometer. Here are some helpful commands:
- Initializing:
PulseInOut xaxis(P5_7);
Initializes a pin as xaxis
to read the x-axis. The same works for the y-axis, just change xaxis
to an appropriate name and change the pin assignment from P5_7
to P6_0
(the attached pin for the y-axis).
- Get accelerometer value:
int x = ((xaxis.read_high_us() / 10) - 500) * 8;
This is essentially the same technique showed in the Mx2125 page on Arduino. x
’s output is in milli-g’s
That’s all you need to do to access the accelerometer!Import the Pulse library, initialize a pin for pulse input/output, and read away!
The last component is the MAX17055 battery gauge. This component is built into the MAX32620FTHR and requires no wiring. Using it is a lot like using the Mx2125: import the library, initialize, read away.
1. Create a new program and import the “MAX17055” library by Team Maxim Integrated
2. Open “main.cpp” in your program and import the program with
#include “MAX17055.h”
No configuration is needed. You can jump right into using it.
- Initializing:
I2C bati(P3_4, P3_5);
MAX17055 bat(bati);
The MAX17055 uses I2C to communicate, so we initialize it as bat
(as in battery) with an unused I2C port on the MAX32620FTHR.
- More initialization for battery status and battery voltage:
int status;
float f_value;
bat.init(0.05f);
bat.status(&status);
The code kind of speaks for itself. You simply are creating variables to store the status and voltage values calculated by the MAX17055, starting up the MAX17055, and getting the status of the battery.
- Getting the voltage:
bat.v_cell(&f_value);
Simply returns the voltage of the connected battery to the variable f_value
which we created earlier
Further documentation on the MAX17055 can be found here.
Congratulations! You now know how to program your InVyu! As you may know, Arm Mbed is a large ecosystem. Anything that is in Arm Mbed’s documentation will work just fine with the MAX32620FTHR. Now, let’s move on to interacting with your InVyu through iOS.
Software: Programming tutorialAs stated before: to keep things simple, this tutorial focuses on using iOS 11/12 and Swift 4. These same techniques can be applied for Android and desktop applications. (Note: prior knowledge/experience with Swift and troubleshooting in Xcode is assumed)
iOS uses a single a library (known as a module) named CoreBluetooth
. With CoreBluetooth
your phone can connect and communicate with Bluetooth peripherals. The HM-10 on your InVyu is no different. As you may have noticed with the Demo app, iOS will quickly seek out your InVyu and automatically connect to it without you having to do anything. Here are the necessary steps to allow your app to communicate with your InVyu:
1.
import CoreBluetooth
CoreBluetooth is a built-in module to iOS so no external downloads are required.
2.
letbtCBUUID = CBUUID(string: "0xFFE0")
let charCBUUID = CBUUID(string: "0xFFE1")
Bluetooth interactions work by using a identifier (for the device) and a characteristic (to send/read values). The HM-10’s identifier is “0xFFE0” and it has one characteristic “0xFFE1
”. We assign these UUIDs to variables so we can access them later.
3.
varwriteType: CBCharacteristicWriteType = .withoutResponse
Simply assigning the write type to a variable. Fake HM-10s may require a different write type, so be careful about them.
4.
var cMan: CBCentralManager!
var btMod: CBPeripheral!
var btChar: CBCharacteristic!
Create variables to hold the Bluetooth interaction objects. The CentralManager
is what it sounds like, the CBPeripheral
is the HM-10, and the CBCharacteristic
is the HM-10’scharacteristic
5.
cMan= CBCentralManager(delegate: self, queue: nil)
add this to viewDidLoad()
to initialize the manager
6.
extension <Name of your Controller>: CBCentralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .unknown:
print("central.state is .unknown")
case .resetting:
print("central.state is .resetting")
case .unsupported:
print("central.state is .unsupported")
case .unauthorized:
print("central.state is .unauthorized")
case .poweredOff:
print("central.state is .poweredOff")
case .poweredOn:
print("central.state is .poweredOn")
cMan.scanForPeripherals(withServices: [btCBUUID])
}
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) {
print(peripheral)
btMod = peripheral
btMod.delegate = self
cMan.stopScan()
cMan.connect(btMod)
}
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
print("Connected to \(peripheral)!")
connected = true
btMod.discoverServices(nil)
}
}
this giant chunk will automatically connect your app to your InVyu. Breaking it down: centralManagerDidUpdateState
simply is a check to see if Bluetooth is on and if the central manager is ready to go, if it is then the manager will go scan for peripherals to connect to; didDiscoverperipheral
will connect to a peripheral when it finds one; and the last function will simply run when a successful connection is made to the peripheral.
7.
extension <Name of your Controller>: CBPeripheralDelegate {
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
guard let services = peripheral.services else { return }
for service in services {
print(service)
peripheral.discoverCharacteristics(nil, for: service)
}
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService,error: Error?) {
guard let characs = service.characteristics else { return }
for charac in characs {
print(charac)
if charac.uuid == charCBUUID {
btMod.setNotifyValue(true, for:charac)
btChar = charac
writeType = charac.properties.contains(.write)? .withResponse : .withoutResponse
print(charac.properties)
}
}
}
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
print("Data incoming")
if characteristic.uuid == charCBUUID {
let data = characteristic.value
let str = String(data: data!, encoding: .utf8)
}
}
}
This next giant chunk gets the characteristic from the peripheral and lets you receive incoming data from your InVyu as a string. The first function discovers characteristics from services from the just connected peripheral. The second function finds the characteristic that matches the one for the HM-10 (0xFFE1
). And the third function reads any incoming data, checksto see if it is from the correct characteristic, and then converts the data intoa string (assigned as str).
8.
if let data = String(<value>).data(using: .utf8) {
btMod!.writeValue(data, for: btChar, type: writeType)
print("Sent \(data)!")
} else {
print("Error with data")
}
This small chuck lets you send string <value>
to your InVyu. The most important line here is btMod!.writeValue(data, for: btChar, type: writeType)
. Breaking this line down, the first parameter is the data (converted from a string in the if let
), the second is which characteristic to send the data to (obviously there's only one characteristic we can send to), and finally what is the write type of the characteristic. as you may have noticed, these parameters use the variables that we created at the very beginning of the Swift file. Everything else is purely for debugging and guarding (so the app won’t crash if an error occurs).
With just those 8 steps, you can make any app interact with your InVyu!
Conclusion: InVyuCongratulations! You now have everything you need to make your own InVyu, your own hackable wearable head up display! Over this tutorial we’ve covered how to assemble the hardware for your InVyu, how to install demo firmware/software to get started, and how to expand your InVyu’s capabilities with your own firmware and software!
Thank you for taking interest in this project! Please leave feedback at the end of this project page and look out for new updates to InVyu!Also, check out my first variant of the maker’s wearable heads-up display: EUD_Dev
Happy hacking!
Comments